Message ID | 20170517135439.25935-2-mwilck@suse.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | christophe varoqui |
Headers | show |
Hi Martin, On 05/17/2017 03:54 PM, Martin Wilck wrote: > Under certain conditions, the output of "multipath -ll" or > "multipathd show topology", or the multipathd logs, may > contain garbage characters. Fix that by making sure that > the strings are always properly zero-terminated. > > Note 1: The way this is coded, the previously written > character is overwritten by the newline. That behavior is > unchanged by this patch. I didn't want to fuzz with the > carefully crafted print.c code more than necessary at > this point. > > Note 2: The condition (c <= line + len - 1) is equivalent to > (TAIL >= 0). It should always hold the way ENDLINE is called > after PRINT and PAD in print.c, and is only added as an > additional safeguard, e.g. against future code changes. ^^ Missing S-o-b
On Wed, 2017-05-17 at 15:54 +0200, Martin Wilck wrote: > #define ENDLINE \ > - if (c > line) \ > - line[c - line - 1] = '\n' > + if (c > line) { \ > + if (c <= line + len - 1) { \ > + *(c - 1) = '\n'; \ > + *c = '\0'; \ > + } else \ > + line[len - 1] = '\0'; \ > + } Hello Martin, Please convert ENDLINE from a macro into a function. Functions are easier to maintain than macros. Thanks, Bart. -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
diff --git a/libmultipath/print.c b/libmultipath/print.c index 7c2a1588..3a07fcf5 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -40,8 +40,14 @@ do { \ } while (0) #define ENDLINE \ - if (c > line) \ - line[c - line - 1] = '\n' + if (c > line) { \ + if (c <= line + len - 1) { \ + *(c - 1) = '\n'; \ + *c = '\0'; \ + } else \ + line[len - 1] = '\0'; \ + } + #define PRINT(var, size, format, args...) \ do { \ fwd = snprintf(var, size, format, ##args); \