build failure with -D_FORTIFY_SOURCE=2
Hi. Just got a build failure with recent gcc with enabled option FORTIFY_SOURCE=2: In function 'strncpy', inlined from 'rip_outgoing_authentication' at ../../../proto/rip/auth.c:134:5: /usr/include/bits/string3.h:120:10: error: call to __builtin___strncpy_chk will always overflow destination buff er return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); ^ make[1]: *** [auth.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]: Leaving directory `/usr/src/RPM/BUILD/bird-1.5.0/build-bird6/proto/rip' make: *** [subdir] Error 2 make: Leaving directory `/usr/src/RPM/BUILD/bird-1.5.0/build-bird6' There is proto/rip/auth.c:134: strncpy( (char *) (&block->packetlen), passwd->password, 16); destination packetlen is u16, so gcc thinks it is overflow. Is it possible to change strncpy with memcpy? -- Vladimir Lettiev aka crux ✉ theCrux@gmail.com
On Sun, Oct 25, 2015 at 05:31:52PM +0300, Vladimir Lettiev wrote:
Hi.
Just got a build failure with recent gcc with enabled option FORTIFY_SOURCE=2:
In function 'strncpy', inlined from 'rip_outgoing_authentication' at ../../../proto/rip/auth.c:134:5: /usr/include/bits/string3.h:120:10: error: call to __builtin___strncpy_chk will always overflow destination buff
There is proto/rip/auth.c:134:
strncpy( (char *) (&block->packetlen), passwd->password, 16);
destination packetlen is u16, so gcc thinks it is overflow.
Is it possible to change strncpy with memcpy?
No, memcpy would not work. You could replace '(char *) (&block->packetlen)' with: (char *) block + OFFSETOF(struct rip_block_auth, packetlen) -- Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: santiago@crfreenet.org) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
On Sun, Oct 25, 2015 at 10:32:33PM +0100, Ondrej Zajicek wrote:
On Sun, Oct 25, 2015 at 05:31:52PM +0300, Vladimir Lettiev wrote:
Hi.
Just got a build failure with recent gcc with enabled option FORTIFY_SOURCE=2:
In function 'strncpy', inlined from 'rip_outgoing_authentication' at ../../../proto/rip/auth.c:134:5: /usr/include/bits/string3.h:120:10: error: call to __builtin___strncpy_chk will always overflow destination buff
There is proto/rip/auth.c:134:
strncpy( (char *) (&block->packetlen), passwd->password, 16);
destination packetlen is u16, so gcc thinks it is overflow.
Is it possible to change strncpy with memcpy?
No, memcpy would not work.
You could replace '(char *) (&block->packetlen)' with:
(char *) block + OFFSETOF(struct rip_block_auth, packetlen)
Thanks, it worked. -- Vladimir Lettiev aka crux ✉ theCrux@gmail.com
participants (2)
-
Ondrej Zajicek -
Vladimir Lettiev