[sheepdog] [PATCH v1] fix null pointer reference in dog command

Meng An isolate000 at gmail.com
Tue Sep 23 05:11:55 CEST 2014


From: Meng An <anmeng.an at alibaba-inc.com>

In function do_generic_subcommand, we should check if argv[optind] is NULL
before using it.

Signed-off-by: Meng An <isolate000 at gmail.com>
---
 dog/common.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/dog/common.c b/dog/common.c
index 3c4f6f5..df49792 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -238,6 +238,9 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 		sd_err("Too deep netsted subcommands, "
 		       "please expand MAX_SUBCMD_DEPTH");
 		exit(EXIT_USAGE);
+	} else if (NULL == argv[optind]) {
+		subcommand_usage(argv[1], argv[2], EXIT_USAGE);
+		exit(EXIT_USAGE);
 	}
 
 	subcmd_stack[++subcmd_depth] = sub;
-- 
1.7.1




More information about the sheepdog mailing list