public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "patrickdepinguin at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103173] strncpy output may be truncated copying 32 bytes from a string of length 1439 (bogus) [-Werror=stringop-truncation] Date: Tue, 21 Dec 2021 15:26:51 +0000 [thread overview] Message-ID: <bug-103173-4-8XPwlGTF6S@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103173-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103173 --- Comment #3 from Thomas De Schampheleire <patrickdepinguin at gmail dot com> --- While the original test program failed on gcc 11.2.0 but not on gcc 9.4.0, I now encounter a very similar case that does fail on gcc 9.4.0: ------------------------------ #include <stdio.h> #define MAX_NR_USERS 10 struct user_data { char user[32]; char password[32]; char application[32]; }; struct user_data users[MAX_NR_USERS]; void login_process() { char tmp_user[33]; for (int i = 0; i < MAX_NR_USERS; i++) { snprintf(tmp_user, sizeof(tmp_user), "%s", &(users[i].user[0])); } } ------------------------------ arm-cortex_a53-linux-gnueabi-gcc /tmp/gcc-9-test.c -c -Wall -O2 /tmp/gcc-9-test.c: In function 'login_process': /tmp/gcc-9-test.c:19:47: warning: '%s' directive output may be truncated writing up to 959 bytes into a region of size 33 [-Wformat-truncation=] 19 | snprintf(tmp_user, sizeof(tmp_user), "%s", &(users[i].user[0])); | ^~ /tmp/gcc-9-test.c:19:9: note: 'snprintf' output between 1 and 960 bytes into a destination of size 33 19 | snprintf(tmp_user, sizeof(tmp_user), "%s", &(users[i].user[0])); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here, the claimed 960 bytes are the total size of 'users' (3 * 32 * 10), while the copied 'user' field is only 33 byte and there should be no problem. The error is now -Wformat-truncation instead of -Wstringop-truncation but otherwise this looks to be the same underlying problem. This compiler is: Using built-in specs. COLLECT_GCC=.../buildroot-toolchains-bis/output/host/opt/ext-toolchain/bin/arm-cortex_a53-linux-gnueabi-gcc COLLECT_LTO_WRAPPER=.../buildroot-toolchains-bis/output/host/opt/ext-toolchain/arm/bin/../libexec/gcc/arm-cortex_a53-linux-gnueabi/9.4.0/lto-wrapper Target: arm-cortex_a53-linux-gnueabi Configured with: .../ctng/crosstool-ng/.build/arm-cortex_a53-linux-gnueabi/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-cortex_a53-linux-gnueabi --prefix=.../ctng/crosstool-ng/targets/arm-cortex_a53-linux-gnueabi --exec_prefix=.../ctng/crosstool-ng/targets/arm-cortex_a53-linux-gnueabi --with-sysroot=.../ctng/crosstool-ng/targets/arm-cortex_a53-linux-gnueabi/arm-cortex_a53-linux-gnueabi/sysroot --enable-languages=c,c++,fortran --with-cpu=cortex-a53 --with-fpu=neon-fp-armv8 --with-float=hard --with-pkgversion='crosstool-NG 1.24.0.487_10ac846' --enable-__cxa_atexit --disable-tm-clone-registry --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=.../ctng/crosstool-ng/.build/arm-cortex_a53-linux-gnueabi/buildtools --with-mpfr=.../ctng/crosstool-ng/.build/arm-cortex_a53-linux-gnueabi/buildtools --with-mpc=.../ctng/crosstool-ng/.build/arm-cortex_a53-linux-gnueabi/buildtools --with-isl=.../ctng/crosstool-ng/.build/arm-cortex_a53-linux-gnueabi/buildtools --disable-lto --without-zstd --enable-threads=posix --enable-target-optspace --disable-plugin --disable-nls --disable-multilib --with-local-prefix=.../ctng/crosstool-ng/targets/arm-cortex_a53-linux-gnueabi/arm-cortex_a53-linux-gnueabi/sysroot --enable-long-long Thread model: posix gcc version 9.4.0 (crosstool-NG 1.24.0.487_10ac846)
next prev parent reply other threads:[~2021-12-21 15:26 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-10 15:40 [Bug tree-optimization/103173] New: " patrickdepinguin at gmail dot com 2021-11-10 19:17 ` [Bug tree-optimization/103173] " msebor at gcc dot gnu.org 2021-11-11 9:15 ` rguenth at gcc dot gnu.org 2021-12-21 15:26 ` patrickdepinguin at gmail dot com [this message] 2021-12-21 15:35 ` patrickdepinguin at gmail dot com 2023-07-20 8:48 ` georgmueller at gmx dot net
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-103173-4-8XPwlGTF6S@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).