[sheepdog] [PATCH] dog/common: check empty argument for commands those need arguments

Ruoyu liangry at ucweb.com
Thu Aug 7 09:03:45 CEST 2014


Advised by Hitoshi:

If we execute a command like this: dog node md plug "",
sheep dies because sheep daemon assumes a path name passed
by dog process is correct.

Response by Ruoyu:

I think the above checking should be processed in framework, too.
Otherwise, we must check it in every function that needs arguments.

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 dog/common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/dog/common.c b/dog/common.c
index 340bbed..2335e14 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -257,7 +257,8 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 		}
 
 		optind++;
-		if (flags & CMD_NEED_ARG && argc == optind)
+		if ((flags & CMD_NEED_ARG) &&
+				(argc == optind || argv[optind][0] == '\0'))
 			subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 		ret = sub[i].fn(argc, argv);
 		if (ret == EXIT_USAGE)
-- 
1.8.3.2




More information about the sheepdog mailing list