Message ID | 20230531021936.7366-7-lizhijian@fujitsu.com |
---|---|
State | Superseded |
Headers | show |
Series | cxl/monitor and ndctl/monitor fixes | expand |
On 5/30/23 19:19, Li Zhijian wrote: > According to the tool's documentation, when '-l standard' is specified, > log would be output to the stdout. But since it's using strncmp(a, b, 10) > to compare the former 10 characters, it will also wrongly detect a > filename starting with a substring 'standard' as stdout. > > For example: > $ ndctl monitor -l standard.log > > User is most likely want to save log to ./standard.log instead of stdout. > > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > V3: Improve commit log # Dave > V2: commit log updated # Dave > --- > ndctl/monitor.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/ndctl/monitor.c b/ndctl/monitor.c > index 89903def63d4..bd8a74863476 100644 > --- a/ndctl/monitor.c > +++ b/ndctl/monitor.c > @@ -610,9 +610,9 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx) > if (monitor.log) { > if (strncmp(monitor.log, "./", 2) != 0) > fix_filename(prefix, (const char **)&monitor.log); > - if (strncmp(monitor.log, "./syslog", 8) == 0) > + if (strcmp(monitor.log, "./syslog") == 0) > monitor.ctx.log_fn = log_syslog; > - else if (strncmp(monitor.log, "./standard", 10) == 0) > + else if (strcmp(monitor.log, "./standard") == 0) > monitor.ctx.log_fn = log_standard; > else { > monitor.ctx.log_file = fopen(monitor.log, "a+");
diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 89903def63d4..bd8a74863476 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -610,9 +610,9 @@ int cmd_monitor(int argc, const char **argv, struct ndctl_ctx *ctx) if (monitor.log) { if (strncmp(monitor.log, "./", 2) != 0) fix_filename(prefix, (const char **)&monitor.log); - if (strncmp(monitor.log, "./syslog", 8) == 0) + if (strcmp(monitor.log, "./syslog") == 0) monitor.ctx.log_fn = log_syslog; - else if (strncmp(monitor.log, "./standard", 10) == 0) + else if (strcmp(monitor.log, "./standard") == 0) monitor.ctx.log_fn = log_standard; else { monitor.ctx.log_file = fopen(monitor.log, "a+");
According to the tool's documentation, when '-l standard' is specified, log would be output to the stdout. But since it's using strncmp(a, b, 10) to compare the former 10 characters, it will also wrongly detect a filename starting with a substring 'standard' as stdout. For example: $ ndctl monitor -l standard.log User is most likely want to save log to ./standard.log instead of stdout. Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> --- V3: Improve commit log # Dave V2: commit log updated # Dave --- ndctl/monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)