You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and this is failing when building against glibc 2.17, of course; follows that our own internal strlcpy implementation gets compiled, but <string.h> header still exposes the strlcpy prototype, leading to a redefinition error.
Relevant bits:
<string.h>:
#if__GNUC_PREREQ (3,4)
# if__USE_FORTIFY_LEVEL>0&& defined __fortify_function/* Functions with security checks. */# include<bits/string_fortified.h># endif#endif
Indeed, patching <bits/string_fortified.h> adding the surrounding guard, properly gives the expected error:
zig cc -target x86_64-linux-gnu.2.17 test.c -o test -D_FORTIFY_SOURCE=2 -O2 -D_GNU_SOURCE
test.c:3:15: error: call to undeclared library function 'strlcpy' with type 'unsigned long (char *, const char *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
3 | char s[10]; strlcpy(s, "foo", sizeof(s));
| ^
test.c:3:15: note: include the header <string.h> or explicitly provide a declaration for 'strlcpy'
1 error generated.
since strlcpy was added to glibc 2.38.
Expected Behavior
I'd expect that no strlcpy / strlcat prototype is included via <string.h> on glibc <2.38 versions, since they were not existing, even with _FORTIFY_SOURCE enabled.
The text was updated successfully, but these errors were encountered:
FedeDP
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Aug 30, 2024
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Source file:
zig cc test.c -o test -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -O2
leads to OK compilation (using glibc 2.38).Targeting instead eg: glibc 2.17 leads to issue:
But the
strlcpy
symbol is actually found (it complains thatstrlcpy
calls__strncpy_chk
that is not defined).This is hitting us because, as many projects, we have a cmake check around
strlcpy
, like:and this is failing when building against glibc 2.17, of course; follows that our own internal
strlcpy
implementation gets compiled, but<string.h>
header still exposes thestrlcpy
prototype, leading to a redefinition error.Relevant bits:
<string.h>
:<bits/string_fortified.h>
My (super wild) guess is that the declaration in
string_fortified.h
must still be surrounded by thecheck.
Indeed, patching
<bits/string_fortified.h>
adding the surrounding guard, properly gives the expected error:since
strlcpy
was added to glibc 2.38.Expected Behavior
I'd expect that no
strlcpy
/strlcat
prototype is included via<string.h>
on glibc <2.38 versions, since they were not existing, even with_FORTIFY_SOURCE
enabled.The text was updated successfully, but these errors were encountered: