Build fails with GCC 8 due to format truncation errors
Building bip with GCC 8 fails, like this:
gcc -DHAVE_CONFIG_H -I. -I./src -Wall -Wextra -Werror -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIE -Wno-unused-result -c -o src/bip.o src/bip.c
src/bip.c: In function 'do_pid_stuff':
src/bip.c:209:27: error: '%s' directive output may be truncated writing up to 1023 bytes into a region of size 1022 [-Werror=format-truncation=]
snprintf(longpath, 1023, "%s.%s.%ld", conf_pid_file, hname,
src/bip.c:209:27: note: using the range [-9223372036854775808, 9223372036854775807] for directive argument
In file included from /usr/include/stdio.h:873,
/usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 4 or more bytes (assuming 1027) into a destination of size 1023
return builtinsnprintf_chk (_s, _n, __USE_FORTIFY_LEVEL - 1,
__bos (_s), __fmt, __va_arg_pack ());
cc1: all warnings being treated as errors
make1: Leaving directory '/builddir/build/BUILD/bip-0.9.0-rc3'
make1: *** [Makefile:515: src/bip.o] Error 1
I have to admit I'm not quite sure why that's happening - I'm no C expert, but it seems to me like hname is declared as being 1024 bytes, not 1022, so I don't know why GCC thinks we're putting 1023 bytes into a 1022 byte region. But maybe someone else can see the problem.
This can be worked around by building with -Wno-error=format-truncation .
#1 Updated by Arnaud Cornet 5 days ago
Per the following the warning is about truncation which can cause various harm (that is not memory stomping, but still quite bad)