From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1A9BA3858C36; Wed, 27 Mar 2024 06:20:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A9BA3858C36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1711520403; bh=2o6ygCusUSIjrORPRRnKx7iFR/S3KolUPkVkp8iZNcc=; h=From:To:Subject:Date:From; b=qq4R+L8Cs5U+m/7V3WSsKWhgveX/7t3lLrCdOgGAFmNxSG3CeywsMA9BD6PyyI/yw 61qA7a4DSvZhYr9RFPzDwzfLtSARg8Pjj2hPtTCfDPZAfGnybIVNiUkRP2wMUAZmgQ C4/fKlGr8SwhjT5WFs8Xm2T28HC3ksTJWztzMEHc= From: "akihiko.odaki at daynix dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/114494] New: false-positive with -O2 -Wstringop-overflow=2 -fsanitize=address Date: Wed, 27 Mar 2024 06:20:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: akihiko.odaki at daynix dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114494 Bug ID: 114494 Summary: false-positive with -O2 -Wstringop-overflow=3D2 -fsanitize=3Daddress Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: akihiko.odaki at daynix dot com CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org Target Milestone: --- Building https://gitlab.com/qemu-project/qemu/-/commits/v9.0.0-rc1?ref_type=3Dtags c= auses the following warning: cc -m64 -mcx16 -Ilibcommon.fa.p -Isubprojects/dtc/libfdt -I../subprojects/dtc/libfdt -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=3D= auto -Wall -Winvalid-pch -Werror -std=3Dgnu11 -O2 -g -fsanitize=3Daddress -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough= =3D2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow= =3Dlocal -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/me/qemu/linux-headers -isystem linux-headers -iquote . -iquote /home/me/qemu -iquote /home/me/qemu/include -iquote /home/me/qemu/host/include/x86_64 -iquote /home/me/qemu/host/include/generic -iquote /home/me/qemu/tcg/i386 -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS= =3D64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=3Dzero -fzero-call-used-regs=3Dused-gpr -fPIE -MD -= MQ libcommon.fa.p/hw_net_rtl8139.c.o -MF libcommon.fa.p/hw_net_rtl8139.c.o.d -o libcommon.fa.p/hw_net_rtl8139.c.o -c ../hw/net/rtl8139.c ../hw/net/rtl8139.c: In function 'rtl8139_io_writeb': ../hw/net/rtl8139.c:2273:17: error: writing 8 bytes into a region of size 0 [-Werror=3Dstringop-overflow=3D] 2273 | memcpy(data_to_checksum, saved_ip_header + 12, 8); Below is a minimized reproduction case: gcc -O2 -Wstringop-overflow=3D2 -fsanitize=3Daddress -c -x c - < struct ip_header { char ip_ver_len; }; void rtl8139_cplus_transmit_one(char *saved_buffer) { struct ip_header *ip; int hlen; char *eth_payload_data =3D saved_buffer + 4; ip =3D (struct ip_header*)eth_payload_data; hlen =3D ip->ip_ver_len; if (hlen < sizeof(struct ip_header)) { return; } char saved_ip_header[1]; memcpy(saved_ip_header, eth_payload_data, hlen); memcpy(eth_payload_data + hlen, saved_ip_header, 1); } EOF=