Project

General

Profile

Actions

Bug #636

closed

Build fails with GCC 8 due to format truncation errors

Added by Adam Williamson over 5 years ago. Updated over 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
2018-09-19
Due date:
% Done:

0%

Estimated time:
Patch Available:
Found in Versions:
0.9.0rc3
Confirmed:
No
Branch:
Security:
Help Needed:

Description

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,
from src/bip.c:16:
/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 .

Actions #1

Updated by Arnaud Cornet over 5 years ago

Per the following the warning is about truncation which can cause various harm (that is not memory stomping, but still quite bad)
https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/

Actions #2

Updated by Arnaud Cornet over 5 years ago

  • Status changed from New to Resolved
Actions

Also available in: Atom PDF