[sheepdog] [PATCH v1] fix null pointer reference in dog command
meng
isolate000 at gmail.com
Tue Sep 23 05:31:46 CEST 2014
在 14-9-23 上午11:25, Ruoyu 写道:
>
> On 2014年09月23日 11:11, Meng An wrote:
>> 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.
> Thanks, but why we should check it first?
for example, if we run the command "dog node log level -a 127.0.0.1"
without setting the subcommand "set/get/list",
it will cause Segment Fault, because in funtion do_generic_subcommand,
we using argv[optind] directly:
***
248 for (i = 0; sub[i].name; i++) {
249 unsigned long flags;
250
251 if (strcmp(sub[i].name, argv[optind]))
252 continue;
253
***
Thanks,
Meng
>>
>> 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;
>
>
More information about the sheepdog
mailing list