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

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Aug 7 09:35:12 CEST 2014


At Thu,  7 Aug 2014 15:03:45 +0800,
Ruoyu wrote:
> 
> 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(-)

Applied, thanks.
Hitoshi

> 
> 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
> 
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list