New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gcc format-truncation warnings on Ubuntu 24.04 #2398
Comments
We tried it in the latest Fedora rawhide with GCC 14 and it does not happen there. I also do not see it on Fedora 40 (also GCC 14) and Fedora 39 which GCC 13.2. So not clear right now if that is Ubuntu specific or not. |
@rst0git Could you provide full preprocessed sources (the |
@fweimer-rh I have attached the content of net.i created with the following gcc command: $ gcc -save-temps -c -O2 -D_GNU_SOURCE -iquote include/ -I ./compel/include/uapi -fno-strict-aliasing -iquote criu/include -iquote include -iquote images -iquote criu/arch/x86/include -iquote . -I/usr/include/libnl3 criu/net.c -o criu/net.d
criu/net.c: In function ‘unix_conf_op’:
criu/net.c:378:72: warning: ‘net/unix/’ directive output truncated writing 9 bytes into a region of size 0 [-Wformat-truncation=]
378 | snprintf(path[i], MAX_CONF_UNIX_PATH, CONF_UNIX_FMT, unix_conf_entries[i]);
| ^~~~~~~~~~
In file included from /usr/include/stdio.h:980,
from /usr/include/libnl3/netlink/netlink.h:9,
from /usr/include/libnl3/netlink/attr.h:9,
from criu/net.c:16:
In function ‘snprintf’,
inlined from ‘unix_conf_op’ at criu/net.c:378:3:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:54:10: note: ‘__builtin___snprintf_chk’ output 24 bytes into a destination of size 0
54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
56 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~
|
Thanks, I can reproduce the warning with
I'll try to look into this further, to see if it's a glibc header issue or more of a GCC thing. |
@fweimer-rh I'm not sure if it is the same warning:
|
@fweimer-rh Note that the following change fixes the problem: diff --git a/criu/net.c b/criu/net.c
index b5c4a6ee3..5486c4484 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -362,7 +362,7 @@ static int ipv6_conf_op(char *tgt, SysctlEntry **conf, int n, int op, SysctlEntr
static int unix_conf_op(SysctlEntry ***rconf, size_t *n, int op)
{
int i, ret = -1, flags = 0;
- char path[ARRAY_SIZE(unix_conf_entries)][MAX_CONF_UNIX_PATH] = {};
+ char path[ARRAY_SIZE(unix_conf_entries)+1][MAX_CONF_UNIX_PATH] = {};
struct sysctl_req req[ARRAY_SIZE(unix_conf_entries)] = {};
SysctlEntry **conf = *rconf; I have attached the content of |
The unix_conf_op function reads the size of the sysctl entry array twice. gcc thinks that it can lead to a time-of-check to time-of-use (TOCTOU) race condition if the array size changes between the two reads. Fixes checkpoint-restore#2398
Building CRIU on Ubuntu 24.04 (with gcc 13.2.0 and glibc 2.39) fails with the following errors:
The text was updated successfully, but these errors were encountered: