<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">在 14-9-23 上午11:43, Ruoyu 写道:<br>
</div>
<blockquote cite="mid:5420EC74.4010006@ucweb.com" type="cite">
<br>
On 2014年09月23日 11:31, meng wrote:
<br>
<blockquote type="cite">
<br>
在 14-9-23 上午11:25, Ruoyu 写道:
<br>
<blockquote type="cite">
<br>
On 2014年09月23日 11:11, Meng An wrote:
<br>
<blockquote type="cite">From: Meng An
<a class="moz-txt-link-rfc2396E" href="mailto:anmeng.an@alibaba-inc.com"><anmeng.an@alibaba-inc.com></a>
<br>
<br>
In function do_generic_subcommand, we should check if
argv[optind] is NULL
<br>
before using it.
<br>
</blockquote>
Thanks, but why we should check it first?
<br>
</blockquote>
for example, if we run the command "dog node log level -a
127.0.0.1" without setting the subcommand "set/get/list",
<br>
it will cause Segment Fault, because in funtion
do_generic_subcommand, we using argv[optind] directly:
<br>
</blockquote>
In my environment, it works fine.
<br>
<br>
$ dog/dog node log level -a 127.0.0.1
<br>
Usage: dog node log level {set|get|list} [-a address] [-p port]
[-h] [-T]
<br>
Available subcommands:
<br>
set set new loglevel
<br>
get get current loglevel
<br>
list list available loglevels
<br>
Options:
<br>
-a, --address specify the daemon address (default:
localhost)
<br>
-p, --port specify the daemon port
<br>
-h, --help display this help and exit
<br>
-T, --time show elapsed time
<br>
<br>
Have you run it on latest master?
<br>
</blockquote>
Thanks, with the latest code, it works now...This issue was already
fixed by Yuan, the commit is :<br>
<meta charset="utf-8">
<span style="color: rgb(33, 63, 77); font-family: Helvetica, arial,
freesans, clean, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol';
font-size: 18px; font-style: normal; font-variant: normal;
font-weight: bold; letter-spacing: normal; line-height:
25.2000007629395px; orphans: auto; text-align: start; text-indent:
0px; text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline
!important; float: none; background-color: rgb(230, 241, 246);">dog/common:
check empty argument for commands those need arguments</span><br>
<br>
Thanks,<br>
Meng<br>
<span style="color: rgb(33, 63, 77); font-family: Helvetica, arial,
freesans, clean, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol';
font-size: 18px; font-style: normal; font-variant: normal;
font-weight: bold; letter-spacing: normal; line-height:
25.2000007629395px; orphans: auto; text-align: start; text-indent:
0px; text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline
!important; float: none; background-color: rgb(230, 241, 246);"></span>
<meta charset="utf-8">
<blockquote cite="mid:5420EC74.4010006@ucweb.com" type="cite">
<blockquote type="cite">
<br>
***
<br>
248 for (i = 0; sub[i].name; i++) {
<br>
249 unsigned long flags;
<br>
250
<br>
251 if (strcmp(sub[i].name, argv[optind]))
<br>
252 continue;
<br>
253
<br>
***
<br>
<br>
Thanks,
<br>
Meng
<br>
<blockquote type="cite">
<blockquote type="cite">
<br>
Signed-off-by: Meng An <a class="moz-txt-link-rfc2396E" href="mailto:isolate000@gmail.com"><isolate000@gmail.com></a>
<br>
---
<br>
dog/common.c | 3 +++
<br>
1 files changed, 3 insertions(+), 0 deletions(-)
<br>
<br>
diff --git a/dog/common.c b/dog/common.c
<br>
index 3c4f6f5..df49792 100644
<br>
--- a/dog/common.c
<br>
+++ b/dog/common.c
<br>
@@ -238,6 +238,9 @@ int do_generic_subcommand(struct
subcommand *sub, int argc, char **argv)
<br>
sd_err("Too deep netsted subcommands, "
<br>
"please expand MAX_SUBCMD_DEPTH");
<br>
exit(EXIT_USAGE);
<br>
+ } else if (NULL == argv[optind]) {
<br>
+ subcommand_usage(argv[1], argv[2], EXIT_USAGE);
<br>
+ exit(EXIT_USAGE);
<br>
}
<br>
subcmd_stack[++subcmd_depth] = sub;
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</body>
</html>