Small multipath fixes
Subsystems (2)
v2 cover Small multipath fixes
Two minor fixes that I found necessary recently.
Both touch potentially bigger issues - the first one print.c, which might need some general overhaul at some time in the future, and the second one the build process of multipath tools, which is currently lacking an "autobuild" mechanism.
My intention at was to keep the patches small and non-controversial, therefore I didn't delve into the big issues just yet.
Changes wrt v1 (suggestions by Bart Van Assche):
- patch 1/2: replaced ENDLINE by a function
- patch 2/2: Removed nonstandard <<< construct, and made sure STACKPROT is only set once per makefile.
Martin Wilck (2):
libmultipath: print.c: make sure lines are 0-terminated
multipath-tools: fix compilation with gcc < 4.9
Makefile.inc | 15 ++++++++++++++- libmultipath/print.c | 25 +++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)
Signature · 1 line
2.12.2
PATCH v2 1/2 libmultipath: print.c: make sure lines are 0-terminated
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.
While touching this code, substitute a function for the complex ENDLINE macro.
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.
--- libmultipath/print.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
libmultipath/print.c +17 -8
@@ -39,9 +39,18 @@ do { \ s = c; \ }while (0 ) -#define ENDLINE \ - if (c > line) \ - line[c - line - 1] = '\n' +static char * +__endline (char *line,size_t len,char *c) +{ +if (c > line) { +if (c >= line + len) + c = line + len -1 ; + *(c -1 ) ='\n' ; + *c ='\0' ; + } +return c; +} + #define PRINT(var, size, format, args...) \ do { \ fwd = snprintf(var, size, format, ##args); \
@@ -802,7 +811,7 @@ snprint_multipath_header (char * line, int len, char * format)PAD (data->width); }while (*f++); -ENDLINE ; +__endline (line, len, c);return (c - line); }
@@ -838,7 +847,7 @@ snprint_multipath (char * line, int len, char * format, buff[0 ] ='\0' ; }while (*f++); -ENDLINE ; +__endline (line, len, c);return (c - line); }
@@ -869,7 +878,7 @@ snprint_path_header (char * line, int len, char * format)PAD (data->width); }while (*f++); -ENDLINE ; +__endline (line, len, c);return (c - line); }
@@ -904,7 +913,7 @@ snprint_path (char * line, int len, char * format,PAD (data->width); }while (*f++); -ENDLINE ; +__endline (line, len, c);return (c - line); }
@@ -938,7 +947,7 @@ snprint_pathgroup (char * line, int len, char * format,PAD (data->width); }while (*f++); -ENDLINE ; +__endline (line, len, c);return (c - line); }
Signature · 1 line
2.12.2
PATCH v2 2/2 multipath-tools: fix compilation with gcc < 4.9
In reply to Martin Wilckgcc supports -fstack-protector-strong since v4.9 only. Add a "poor man's autoconf" test to check whether the option is supported on the given build system.
"multipath-tools: Replace -fstack-protector with -fstack-protector-strong"
--- Makefile.inc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
Makefile.inc +14 -1
@@ -69,10 +69,23 @@ RM = rm -f LN = ln -sf INSTALL_PROGRAM = install +# $(call TEST_CC_OPTION,option,fallback) +# Test if the C compiler supports the option. +# Evaluates to "option" if yes, and "fallback" otherwise. +TEST_CC_OPTION = $(shell \ + if echo 'int main(void){return 0;}' | $(CC) -o /dev/null -c "$(1)" -xc - &>/dev/null; \ + then \ + echo "$(1)"; \ + else \ + echo "$(2)"; \ + fi) + +STACKPROT := $(call TEST_CC_OPTION,-fstack-protector-strong,-fstack-protector) + OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ -Werror=implicit-function-declaration -Werror=format-security \ -Wno-sign-compare -Wno-unused-parameter -Wno-clobbered \ - -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong \ + -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \ --param=ssp-buffer-size=4 CFLAGS = $(OPTFLAGS) -fPIC -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\"
Signature · 1 line
2.12.2
v2 of this set is merged.
Thanks.
Quoted 28 lines · Martin Wilck
Two minor fixes that I found necessary recently.
Both touch potentially bigger issues - the first one
print.c, which might need some general overhaul at some time in the future, and the second one the build process of multipath tools, which is currently lacking an "autobuild" mechanism.My intention at was to keep the patches small and non-controversial, therefore I didn't delve into the big issues just yet.
Changes wrt v1 (suggestions by Bart Van Assche):
- patch 1/2: replaced ENDLINE by a function
- patch 2/2: Removed nonstandard <<< construct, and made sure STACKPROT is only
set once per makefile.Martin Wilck (2):
libmultipath:print.c: make sure lines are 0-terminated
multipath-tools: fix compilation with gcc < 4.9Makefile.inc | 15 ++++++++++++++- libmultipath/print.c | 25 +++++++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-)--
2.12.2