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

meng isolate000 at gmail.com
Tue Sep 23 06:59:35 CEST 2014


在 14-9-23 上午11:43, Ruoyu 写道:
>
> On 2014年09月23日 11:31, meng wrote:
>>
>> 在 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:
> In my environment, it works fine.
>
> $ dog/dog node log level -a 127.0.0.1
> Usage: dog node log level {set|get|list} [-a address] [-p port] [-h] [-T]
> Available subcommands:
>   set                     set new loglevel
>   get                     get current loglevel
>   list                    list available loglevels
> Options:
>   -a, --address           specify the daemon address (default: localhost)
>   -p, --port              specify the daemon port
>   -h, --help              display this help and exit
>   -T, --time              show elapsed time
>
> Have you run it on latest master?
Thanks, with the latest code, it works now...This issue was already 
fixed by Yuan, the commit is :
dog/common: check empty argument for commands those need arguments

Thanks,
Meng
>>
>> ***
>> 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;
>>>
>>>
>>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20140923/d647cd21/attachment-0004.html>


More information about the sheepdog mailing list