diff mbox

[ndctl,1/2] ndctl: fix a segfault in parse-options.c

Message ID 1463791855-24615-2-git-send-email-vishal.l.verma@intel.com (mailing list archive)
State Accepted
Commit 0f50e5814dad
Headers show

Commit Message

Verma, Vishal L May 21, 2016, 12:50 a.m. UTC
Running something like ndctl create-namespace --list-cmds
would reliably sigfault ndctl due to a null pointer dereference.

Add a check before the dereference to fix it.

Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 util/parse-options.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn May 23, 2016, 7:55 a.m. UTC | #1
On Fri, May 20, 2016 at 06:50:54PM -0600, Vishal Verma wrote:
> Running something like ndctl create-namespace --list-cmds
> would reliably sigfault ndctl due to a null pointer dereference.
> 
> Add a check before the dereference to fix it.
> 
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
diff mbox

Patch

diff --git a/util/parse-options.c b/util/parse-options.c
index f170eb0..387eecd 100644
--- a/util/parse-options.c
+++ b/util/parse-options.c
@@ -472,8 +472,9 @@  int parse_options_subcommand(int argc, const char **argv, const struct option *o
 		}
 		exit(130);
 	case PARSE_OPT_LIST_SUBCMDS:
-		for (int i = 0; subcommands[i]; i++)
-			printf("%s ", subcommands[i]);
+		if (subcommands)
+			for (int i = 0; subcommands[i]; i++)
+				printf("%s ", subcommands[i]);
 		exit(130);
 	default: /* PARSE_OPT_UNKNOWN */
 		if (ctx.argv[0][1] == '-') {