From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082081130583.5714522203; Thu, 4 Jan 2018 08:08:01 -0800 (PST) Received: from localhost ([::1]:46937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX83e-0007SK-CS for importer@patchew.org; Thu, 04 Jan 2018 11:07:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX81z-0006WH-FN for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX81t-00019z-CY for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX81t-00017a-63 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 658ADAE451 for ; Thu, 4 Jan 2018 16:06:04 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57DC8909E9; Thu, 4 Jan 2018 16:05:39 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:06 +0100 Message-Id: <20180104160523.22995-2-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 04 Jan 2018 16:06:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 01/18] build-sys: fix qemu-ga -pthread linking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When linking qemu-ga under some configuration (when gthread-2.0.pc doesn't have -pthread, as happening atm with meson build), you may have this linking issue: /usr/bin/ld: libqemuutil.a(qemu-thread-posix.o): undefined reference to sym= bol 'pthread_setname_np@@GLIBC_2.12' /usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command = line Make sure qemu-ga links with the pthread library, by adding correct flags to libs_qga. This is really a QEMU bug, because it's QEMU code that's using pthread functions, and so we must explicitly link against pthreads. The bug was just masked by the fact that often some pkg-config or another for one of our dependencies will add -pthread to the link line anyway. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Peter Maydell --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index 100309c33f..de1f939a28 100755 --- a/configure +++ b/configure @@ -3445,6 +3445,7 @@ else done if test "$found" =3D "no"; then LIBS=3D"$pthread_lib $LIBS" + libs_qga=3D"$pthread_lib $libs_qga" fi PTHREAD_LIB=3D"$pthread_lib" break --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082107160820.4994303967904; Thu, 4 Jan 2018 08:08:27 -0800 (PST) Received: from localhost ([::1]:46947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84A-0007rE-86 for importer@patchew.org; Thu, 04 Jan 2018 11:08:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX82M-0006nx-Ib for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX82I-00020P-UZ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59984) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX82I-0001yX-O8 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:30 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E66965F160 for ; Thu, 4 Jan 2018 16:06:29 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16F677A245; Thu, 4 Jan 2018 16:06:05 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:07 +0100 Message-Id: <20180104160523.22995-3-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 04 Jan 2018 16:06:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 02/18] build-sys: silence make by default or V=0 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move generic make flags in MAKEFLAGS (SUBDIR_MAKEFLAGS is more qemu specifi= c). Use --quiet to silence make 'is up to date' message. Signed-off-by: Marc-Andr=C3=A9 Lureau Tested-by: Eric Blake Reviewed-by: Paolo Bonzini --- Makefile | 2 +- rules.mak | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d86ecd2dd4..1671db3bdd 100644 --- a/Makefile +++ b/Makefile @@ -277,7 +277,7 @@ else DOCS=3D endif =20 -SUBDIR_MAKEFLAGS=3D$(if $(V),,--no-print-directory) BUILD_DIR=3D$(BUILD_DI= R) +SUBDIR_MAKEFLAGS=3DBUILD_DIR=3D$(BUILD_DIR) SUBDIR_DEVICES_MAK=3D$(patsubst %, %/config-devices.mak, $(TARGET_DIRS)) SUBDIR_DEVICES_MAK_DEP=3D$(patsubst %, %-config-devices.mak.d, $(TARGET_DI= RS)) =20 diff --git a/rules.mak b/rules.mak index 6e943335f3..5fb4951561 100644 --- a/rules.mak +++ b/rules.mak @@ -131,6 +131,8 @@ modules: # If called with only a single argument, will print nothing in quiet mode. quiet-command =3D $(if $(V),$1,$(if $(2),@printf " %-7s %s\n" $2 $3 && $1= , @$1)) =20 +MAKEFLAGS +=3D $(if $(V),,--no-print-directory --quiet) + # cc-option # Usage: CFLAGS+=3D$(call cc-option, -falign-functions=3D0, -malign-functi= ons=3D0) =20 --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082250355956.679751631511; Thu, 4 Jan 2018 08:10:50 -0800 (PST) Received: from localhost ([::1]:46987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX86T-0001eU-Fu for importer@patchew.org; Thu, 04 Jan 2018 11:10:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX82m-000794-RQ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX82j-0002x7-6a for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX82j-0002vY-14 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:06:57 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E6A2C056870 for ; Thu, 4 Jan 2018 16:06:56 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D02C80620; Thu, 4 Jan 2018 16:06:31 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:08 +0100 Message-Id: <20180104160523.22995-4-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 04 Jan 2018 16:06:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 03/18] build-sys: add a rule to print a variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" $ make print-CFLAGS CFLAGS=3D-fsanitize=3Daddress -Og -g Trick from various sources: https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in= -makefile https://www.cmcrossroads.com/article/printing-value-makefile-variable Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- Makefile | 5 ++++- docs/devel/build-system.txt | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1671db3bdd..f26ef1b1df 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,12 @@ SRC_PATH=3D. =20 UNCHECKED_GOALS :=3D %clean TAGS cscope ctags dist \ html info pdf txt \ - help check-help \ + help check-help print-% \ docker docker-% vm-test vm-build-% =20 +print-%: + @echo '$*=3D$($*)' + # All following code might depend on configuration variables ifneq ($(wildcard config-host.mak),) # Put the all: rule here so that config-host.mak can contain dependencies. diff --git a/docs/devel/build-system.txt b/docs/devel/build-system.txt index 386ef36ee3..52501f2ad9 100644 --- a/docs/devel/build-system.txt +++ b/docs/devel/build-system.txt @@ -510,3 +510,16 @@ default-configs/$TARGET-NAME file as input. This is the entrypoint used when make recurses to build a single system or userspace emulator target. It is merely a symlink back to the Makefile.target in the top level. + + +Useful make targets +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +- help + + Print a help message for the most common build targets. + +- print-VAR + + Print the value of the variable VAR. Useful for debugging the build + system. --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082320763580.0929375469731; Thu, 4 Jan 2018 08:12:00 -0800 (PST) Received: from localhost ([::1]:47032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX87b-0002vV-ST for importer@patchew.org; Thu, 04 Jan 2018 11:11:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX82z-0007KL-Un for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX82w-0003Qp-43 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33032) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX82v-0003PA-SE for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F72A5FD76 for ; Thu, 4 Jan 2018 16:07:09 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2D366090C; Thu, 4 Jan 2018 16:06:57 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:09 +0100 Message-Id: <20180104160523.22995-5-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 04 Jan 2018 16:07:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/18] build-sys: compile with -Og or -O1 when --enable-debug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When --enable-debug is turned on, configure doesn't set -O level, and uses default compiler -O0 level, which is slow. Instead, use -Og if supported by the compiler (optimize debugging experience), or -O1 (keeps code somewhat debuggable and works around compiler bugs). Unfortunately, gcc has many false-positive maybe-uninitialized errors with Og and O1 (f27 gcc 7.2.1 20170915): /home/elmarco/src/qemu/hw/ipmi/isa_ipmi_kcs.c: In function =E2=80=98ipmi_kc= s_ioport_read=E2=80=99: /home/elmarco/src/qemu/hw/ipmi/isa_ipmi_kcs.c:279:12: error: =E2=80=98ret= =E2=80=99 may be used uninitialized in this function [-Werror=3Dmaybe-unini= tialized] return ret; ^~~ cc1: all warnings being treated as errors make: *** [/home/elmarco/src/qemu/rules.mak:66: hw/ipmi/isa_ipmi_kcs.o] Err= or 1 make: *** Waiting for unfinished jobs.... /home/elmarco/src/qemu/hw/ide/ahci.c: In function =E2=80=98ahci_populate_sg= list=E2=80=99: /home/elmarco/src/qemu/hw/ide/ahci.c:903:58: error: =E2=80=98tbl_entry_size= =E2=80=99 may be used uninitialized in this function [-Werror=3Dmaybe-unini= tialized] if ((off_idx =3D=3D -1) || (off_pos < 0) || (off_pos > tbl_entry_s= ize)) { ~~~~~~~~~^~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [/home/elmarco/src/qemu/rules.mak:66: hw/ide/ahci.o] Error 1 /home/elmarco/src/qemu/hw/display/qxl.c: In function =E2=80=98qxl_add_memsl= ot=E2=80=99: /home/elmarco/src/qemu/hw/display/qxl.c:1397:52: error: =E2=80=98pci_start= =E2=80=99 may be used uninitialized in this function [-Werror=3Dmaybe-unini= tialized] memslot.virt_end =3D virt_start + (guest_end - pci_start); ~~~~~~~~~~~~~^~~~~~~~~~~~ /home/elmarco/src/qemu/hw/display/qxl.c:1389:9: error: =E2=80=98pci_region= =E2=80=99 may be used uninitialized in this function [-Werror=3Dmaybe-unini= tialized] qxl_set_guest_bug(d, "%s: pci_region =3D %d", __func__, pci_region= ); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors There seems to be a long list of related bugs in upstream GCC, some of them are being fixed very recently: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D24639 For now, let's workaround it by using Wno-maybe-uninitialized (gcc-only). Suggested-by: Paolo Bonzini Signed-off-by: Marc-Andr=C3=A9 Lureau Tested-by: Philippe Mathieu-Daud=C3=A9 --- configure | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/configure b/configure index de1f939a28..3953859314 100755 --- a/configure +++ b/configure @@ -5160,8 +5160,19 @@ if test "$gcov" =3D "yes" ; then LDFLAGS=3D"-fprofile-arcs -ftest-coverage $LDFLAGS" elif test "$fortify_source" =3D "yes" ; then CFLAGS=3D"-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3D2 $CFLAGS" -elif test "$debug" =3D "no"; then - CFLAGS=3D"-O2 $CFLAGS" +elif test "$debug" =3D "yes"; then + if compile_prog "-Og" ""; then + CFLAGS=3D"-Og $CFLAGS" + elif compile_prog "-O1" ""; then + CFLAGS=3D"-O1 $CFLAGS" + fi + # Workaround GCC false-positive Wuninitialized bugs with Og or O1: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D24639 + if cc_has_warning_flag "-Wno-maybe-uninitialized"; then + CFLAGS=3D"-Wno-maybe-uninitialized $CFLAGS" + fi +else + CFLAGS=3D"-O2 $CFLAGS" fi =20 ########################################## --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151508240014915.051829327814517; Thu, 4 Jan 2018 08:13:20 -0800 (PST) Received: from localhost ([::1]:47070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX88t-0004Ed-5S for importer@patchew.org; Thu, 04 Jan 2018 11:13:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX83F-0007Wp-8k for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX83E-0003oB-Dh for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42122) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX83E-0003nI-7P for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7078187634; Thu, 4 Jan 2018 16:07:27 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A1674FA21; Thu, 4 Jan 2018 16:07:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:10 +0100 Message-Id: <20180104160523.22995-6-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 16:07:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 05/18] tests/docker: add some sanitizers to fedora dockerfile X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Build fedora image with ASAN/UBSan support. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- tests/docker/dockerfiles/fedora.docker | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfi= les/fedora.docker index 4b26c3aded..32de731675 100644 --- a/tests/docker/dockerfiles/fedora.docker +++ b/tests/docker/dockerfiles/fedora.docker @@ -3,7 +3,7 @@ ENV PACKAGES \ ccache gettext git tar PyYAML sparse flex bison python2 bzip2 hostname= \ glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \ gcc gcc-c++ clang make perl which bc findutils libaio-devel \ - nettle-devel \ + nettle-devel libasan libubsan \ mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-confi= g \ mingw32-gtk2 mingw32-gtk3 mingw32-gnutls mingw32-nettle mingw32-libtas= n1 \ mingw32-libjpeg-turbo mingw32-libpng mingw32-curl mingw32-libssh2 \ @@ -15,4 +15,4 @@ ENV PACKAGES \ =20 RUN dnf install -y $PACKAGES RUN rpm -q $PACKAGES | sort > /packages.txt -ENV FEATURES mingw clang pyyaml +ENV FEATURES mingw clang pyyaml asan --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151508218159568.13348604070052; Thu, 4 Jan 2018 08:09:41 -0800 (PST) Received: from localhost ([::1]:46968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX85M-0000aq-PN for importer@patchew.org; Thu, 04 Jan 2018 11:09:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX83O-0007fd-63 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX83K-0003uv-G9 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX83K-0003tt-9L for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:34 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7922DD7136; Thu, 4 Jan 2018 16:07:33 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8E697DB54; Thu, 4 Jan 2018 16:07:28 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:11 +0100 Message-Id: <20180104160523.22995-7-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jan 2018 16:07:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 06/18] tests/docker: add test-debug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new test with --enable-debug using clang/asan/ubsan, remove --enable-debug from test-clang & test-mingw. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- tests/docker/test-clang | 2 +- tests/docker/test-debug | 26 ++++++++++++++++++++++++++ tests/docker/test-mingw | 2 -- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100755 tests/docker/test-debug diff --git a/tests/docker/test-clang b/tests/docker/test-clang index 1eb61a3af7..e90a793178 100755 --- a/tests/docker/test-clang +++ b/tests/docker/test-clang @@ -17,7 +17,7 @@ requires clang =20 cd "$BUILD_DIR" =20 -OPTS=3D"--enable-debug --cxx=3Dclang++ --cc=3Dclang --host-cc=3Dclang" +OPTS=3D"--cxx=3Dclang++ --cc=3Dclang --host-cc=3Dclang" # -fsanitize=3Dundefined is broken on Fedora 23, skip it for now # See also: https://bugzilla.redhat.com/show_bug.cgi?id=3D1263834 #OPTS=3D"$OPTS --extra-cflags=3D-fsanitize=3Dundefined \ diff --git a/tests/docker/test-debug b/tests/docker/test-debug new file mode 100755 index 0000000000..d020b06917 --- /dev/null +++ b/tests/docker/test-debug @@ -0,0 +1,26 @@ +#!/bin/bash -e +# +# Compile and check with clang & --enable-debug. +# +# Copyright (c) 2016-2018 Red Hat Inc. +# +# Authors: +# Fam Zheng +# Marc-Andr=C3=A9 Lureau +# +# This work is licensed under the terms of the GNU GPL, version 2 +# or (at your option) any later version. See the COPYING file in +# the top-level directory. + +. common.rc + +requires clang asan + +cd "$BUILD_DIR" + +OPTS=3D"--cxx=3Dclang++ --cc=3Dclang --host-cc=3Dclang" +OPTS=3D"--enable-debug $OPTS" + +build_qemu $OPTS +make $MAKEFLAGS check +install_qemu diff --git a/tests/docker/test-mingw b/tests/docker/test-mingw index 39a1da448e..503a6bc6f7 100755 --- a/tests/docker/test-mingw +++ b/tests/docker/test-mingw @@ -22,7 +22,6 @@ for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do TARGET_LIST=3D${TARGET_LIST:-$DEF_TARGET_LIST} \ build_qemu --cross-prefix=3D$prefix \ --enable-trace-backends=3Dsimple \ - --enable-debug \ --enable-gnutls \ --enable-nettle \ --enable-curl \ @@ -35,4 +34,3 @@ for prefix in x86_64-w64-mingw32- i686-w64-mingw32-; do make clean =20 done - --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082357759153.8165849553634; Thu, 4 Jan 2018 08:12:37 -0800 (PST) Received: from localhost ([::1]:47069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX88C-0003b4-RJ for importer@patchew.org; Thu, 04 Jan 2018 11:12:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX83j-00081H-I2 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX83i-0004Tu-R2 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:11766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX83i-0004Su-Kd for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:07:58 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D60BCC051664 for ; Thu, 4 Jan 2018 16:07:57 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97A868CCE3; Thu, 4 Jan 2018 16:07:34 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:12 +0100 Message-Id: <20180104160523.22995-8-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 04 Jan 2018 16:07:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 07/18] build-sys: add some sanitizers when --enable-debug if possible X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Enable ASAN/UBSan by default if the compiler supports it. Typical slowdown introduced by AddressSanitizer is 2x. UBSan shouldn't have much impact on runtime cost. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 --- configure | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure b/configure index 3953859314..de1477c93a 100755 --- a/configure +++ b/configure @@ -5161,6 +5161,13 @@ if test "$gcov" =3D "yes" ; then elif test "$fortify_source" =3D "yes" ; then CFLAGS=3D"-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3D2 $CFLAGS" elif test "$debug" =3D "yes"; then + write_c_skeleton; + if compile_prog "-fsanitize=3Daddress" ""; then + CFLAGS=3D"-fsanitize=3Daddress $CFLAGS" + fi + if compile_prog "-fsanitize=3Dundefined" ""; then + CFLAGS=3D"-fsanitize=3Dundefined $CFLAGS" + fi if compile_prog "-Og" ""; then CFLAGS=3D"-Og $CFLAGS" elif compile_prog "-O1" ""; then --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082574141332.6525777885322; Thu, 4 Jan 2018 08:16:14 -0800 (PST) Received: from localhost ([::1]:47178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Bc-0007i3-6C for importer@patchew.org; Thu, 04 Jan 2018 11:16:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX83u-00089Q-JO for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX83q-0004bI-TZ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX83q-0004aD-Nj for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E441D68571 for ; Thu, 4 Jan 2018 16:08:05 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBBAC7FB61; Thu, 4 Jan 2018 16:07:58 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:13 +0100 Message-Id: <20180104160523.22995-9-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 04 Jan 2018 16:08:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 08/18] tests: fix check-qobject leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" /public/qobject_is_equal_conversion: OK =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D14396=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 56 byte(s) in 1 object(s) allocated from: #0 0x7f07682c5850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x7f0767d12f0c in g_malloc ../glib/gmem.c:94 #2 0x7f0767d131cf in g_malloc_n ../glib/gmem.c:331 #3 0x562bd767371f in do_test_equality /home/elmarco/src/qq/tests/check-= qobject.c:49 #4 0x562bd7674a35 in qobject_is_equal_dict_test /home/elmarco/src/qq/te= sts/check-qobject.c:267 #5 0x7f0767d37b04 in test_case_run ../glib/gtestutils.c:2237 #6 0x7f0767d37ec4 in g_test_run_suite_internal ../glib/gtestutils.c:2321 #7 0x7f0767d37f6d in g_test_run_suite_internal ../glib/gtestutils.c:2333 #8 0x7f0767d38184 in g_test_run_suite ../glib/gtestutils.c:2408 #9 0x7f0767d36e0d in g_test_run ../glib/gtestutils.c:1674 #10 0x562bd7674e75 in main /home/elmarco/src/qq/tests/check-qobject.c:3= 27 #11 0x7f0766009039 in __libc_start_main (/lib64/libc.so.6+0x21039) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/check-qobject.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/check-qobject.c b/tests/check-qobject.c index 03e9175113..710f9e6b0a 100644 --- a/tests/check-qobject.c +++ b/tests/check-qobject.c @@ -59,6 +59,8 @@ static void do_test_equality(bool expected, int _, ...) g_assert(qobject_is_equal(args[i], args[j]) =3D=3D expected); } } + + g_free(args); } =20 #define check_equal(...) \ --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082762484522.2955346571144; Thu, 4 Jan 2018 08:19:22 -0800 (PST) Received: from localhost ([::1]:47312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Ej-0002WM-Jh for importer@patchew.org; Thu, 04 Jan 2018 11:19:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84B-0008Q0-BT for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX847-0004q1-LP for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX847-0004pG-F1 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:23 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB4428B107 for ; Thu, 4 Jan 2018 16:08:22 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98A3580607; Thu, 4 Jan 2018 16:08:07 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:14 +0100 Message-Id: <20180104160523.22995-10-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 04 Jan 2018 16:08:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/18] vl: fix direct firmware directories leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Note that data_dir[] will now point to allocated strings. Fixes: Direct leak of 16 byte(s) in 1 object(s) allocated from: #0 0x7f1448181850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x7f1446ed8f0c in g_malloc ../glib/gmem.c:94 #2 0x7f1446ed91cf in g_malloc_n ../glib/gmem.c:331 #3 0x7f1446ef739a in g_strsplit ../glib/gstrfuncs.c:2364 #4 0x55cf276439d7 in main /home/elmarco/src/qq/vl.c:4311 #5 0x7f143dfad039 in __libc_start_main (/lib64/libc.so.6+0x21039) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- vl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vl.c b/vl.c index d3a5c5d021..8430b0c731 100644 --- a/vl.c +++ b/vl.c @@ -2318,7 +2318,7 @@ static void qemu_add_data_dir(const char *path) return; /* duplicate */ } } - data_dir[data_dir_idx++] =3D path; + data_dir[data_dir_idx++] =3D g_strdup(path); } =20 static inline bool nonempty_str(const char *str) @@ -3079,7 +3079,7 @@ int main(int argc, char **argv, char **envp) Error *main_loop_err =3D NULL; Error *err =3D NULL; bool list_data_dirs =3D false; - char **dirs; + char *dir, **dirs; typedef struct BlockdevOptions_queue { BlockdevOptions *bdo; Location loc; @@ -4263,9 +4263,12 @@ int main(int argc, char **argv, char **envp) for (i =3D 0; dirs[i] !=3D NULL; i++) { qemu_add_data_dir(dirs[i]); } + g_strfreev(dirs); =20 /* try to find datadir relative to the executable path */ - qemu_add_data_dir(os_find_datadir()); + dir =3D os_find_datadir(); + qemu_add_data_dir(dir); + g_free(dir); =20 /* add the datadir specified when building */ qemu_add_data_dir(CONFIG_QEMU_DATADIR); --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082942043390.13628162917416; Thu, 4 Jan 2018 08:22:22 -0800 (PST) Received: from localhost ([::1]:47562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Hd-0005Ij-8B for importer@patchew.org; Thu, 04 Jan 2018 11:22:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84c-0000Nd-WF for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX84Z-0005FY-9t for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48952) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX84Z-0005Eu-0y for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4322E1A4081 for ; Thu, 4 Jan 2018 16:08:50 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ECA55DD60; Thu, 4 Jan 2018 16:08:24 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:15 +0100 Message-Id: <20180104160523.22995-11-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 04 Jan 2018 16:08:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 10/18] readline: add a free function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, Markus Armbruster , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Fixes leaks such as: Direct leak of 2 byte(s) in 1 object(s) allocated from: #0 0x7eff58beb850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x7eff57942f0c in g_malloc ../glib/gmem.c:94 #2 0x7eff579431cf in g_malloc_n ../glib/gmem.c:331 #3 0x7eff5795f6eb in g_strdup ../glib/gstrfuncs.c:363 #4 0x55db720f1d46 in readline_hist_add /home/elmarco/src/qq/util/readli= ne.c:258 #5 0x55db720f2d34 in readline_handle_byte /home/elmarco/src/qq/util/rea= dline.c:387 #6 0x55db71539d00 in monitor_read /home/elmarco/src/qq/monitor.c:3896 #7 0x55db71f9be35 in qemu_chr_be_write_impl /home/elmarco/src/qq/charde= v/char.c:167 #8 0x55db71f9bed3 in qemu_chr_be_write /home/elmarco/src/qq/chardev/cha= r.c:179 #9 0x55db71fa013c in fd_chr_read /home/elmarco/src/qq/chardev/char-fd.c= :66 #10 0x55db71fe18a8 in qio_channel_fd_source_dispatch /home/elmarco/src/= qq/io/channel-watch.c:84 #11 0x7eff5793a90b in g_main_dispatch ../glib/gmain.c:3182 #12 0x7eff5793b7ac in g_main_context_dispatch ../glib/gmain.c:3847 #13 0x55db720af3bd in glib_pollfds_poll /home/elmarco/src/qq/util/main-= loop.c:214 #14 0x55db720af505 in os_host_main_loop_wait /home/elmarco/src/qq/util/= main-loop.c:261 #15 0x55db720af6d6 in main_loop_wait /home/elmarco/src/qq/util/main-loo= p.c:515 #16 0x55db7184e0de in main_loop /home/elmarco/src/qq/vl.c:1995 #17 0x55db7185e956 in main /home/elmarco/src/qq/vl.c:4914 #18 0x7eff4ea17039 in __libc_start_main (/lib64/libc.so.6+0x21039) (while at it, use g_new0(ReadLineState), it's a bit easier to read) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/readline.h | 1 + monitor.c | 2 +- util/readline.c | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/qemu/readline.h b/include/qemu/readline.h index c08cf7400e..e81258322b 100644 --- a/include/qemu/readline.h +++ b/include/qemu/readline.h @@ -59,5 +59,6 @@ ReadLineState *readline_init(ReadLinePrintfFunc *printf_f= unc, ReadLineFlushFunc *flush_func, void *opaque, ReadLineCompletionFunc *completion_finder); +void readline_free(ReadLineState *rs); =20 #endif /* READLINE_H */ diff --git a/monitor.c b/monitor.c index d682eee2d8..b9da5e20d1 100644 --- a/monitor.c +++ b/monitor.c @@ -583,7 +583,7 @@ static void monitor_data_destroy(Monitor *mon) if (monitor_is_qmp(mon)) { json_message_parser_destroy(&mon->qmp.parser); } - g_free(mon->rs); + readline_free(mon->rs); QDECREF(mon->outbuf); qemu_mutex_destroy(&mon->out_lock); } diff --git a/util/readline.c b/util/readline.c index bbdee790b0..24ec839854 100644 --- a/util/readline.c +++ b/util/readline.c @@ -500,12 +500,28 @@ const char *readline_get_history(ReadLineState *rs, u= nsigned int index) return rs->history[index]; } =20 +void readline_free(ReadLineState *rs) +{ + int i; + + if (!rs) { + return; + } + for (i =3D 0; i < READLINE_MAX_CMDS; i++) { + g_free(rs->history[i]); + } + for (i =3D 0; i < READLINE_MAX_COMPLETIONS; i++) { + g_free(rs->completions[i]); + } + g_free(rs); +} + ReadLineState *readline_init(ReadLinePrintfFunc *printf_func, ReadLineFlushFunc *flush_func, void *opaque, ReadLineCompletionFunc *completion_finder) { - ReadLineState *rs =3D g_malloc0(sizeof(*rs)); + ReadLineState *rs =3D g_new0(ReadLineState, 1); =20 rs->hist_entry =3D -1; rs->opaque =3D opaque; --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082498238782.2712163599656; Thu, 4 Jan 2018 08:14:58 -0800 (PST) Received: from localhost ([::1]:47172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8AR-0006HH-E2 for importer@patchew.org; Thu, 04 Jan 2018 11:14:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84i-0000VK-CO for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX84h-0005OZ-Hq for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX84h-0005No-Bq for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:08:59 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9417B6B25B for ; Thu, 4 Jan 2018 16:08:58 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26E2080600; Thu, 4 Jan 2018 16:08:52 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:16 +0100 Message-Id: <20180104160523.22995-12-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 04 Jan 2018 16:08:58 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 11/18] tests: fix migration-test leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, Juan Quintela , "Dr. David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Direct leak of 12 byte(s) in 2 object(s) allocated from: #0 0x7f50d403c850 in malloc (/lib64/libasan.so.4+0xde850) #1 0x7f50d1ddf98f in vasprintf (/lib64/libc.so.6+0x8098f) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/migration-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/migration-test.c b/tests/migration-test.c index be598d3257..799e24ebc6 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -358,13 +358,14 @@ static void migrate_check_parameter(QTestState *who, = const char *parameter, const char *value) { QDict *rsp, *rsp_return; - const char *result; + char *result; =20 rsp =3D wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); rsp_return =3D qdict_get_qdict(rsp, "return"); result =3D g_strdup_printf("%" PRId64, qdict_get_try_int(rsp_return, parameter, -1)= ); g_assert_cmpstr(result, =3D=3D, value); + g_free(result); QDECREF(rsp); } =20 --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082579090207.47333588442234; Thu, 4 Jan 2018 08:16:19 -0800 (PST) Received: from localhost ([::1]:47179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Bm-0007xb-7j for importer@patchew.org; Thu, 04 Jan 2018 11:16:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84v-0000hW-Kh for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX84r-0005YF-Vv for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX84r-0005XM-N2 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:09 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E801C5B2FD for ; Thu, 4 Jan 2018 16:09:08 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 546625DAB3; Thu, 4 Jan 2018 16:09:00 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:17 +0100 Message-Id: <20180104160523.22995-13-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 16:09:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 12/18] crypto: fix stack-buffer-overflow error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" ASAN complains about: =3D=3D8856=3D=3DERROR: AddressSanitizer: stack-buffer-overflow on address 0= x7ffd8a1fe168 at pc 0x561136cb4451 bp 0x7ffd8a1fe130 sp 0x7ffd8a1fd8e0 READ of size 16 at 0x7ffd8a1fe168 thread T0 #0 0x561136cb4450 in __asan_memcpy (/home/elmarco/src/qq/build/tests/te= st-crypto-ivgen+0x110450) #1 0x561136d2a6a7 in qcrypto_ivgen_essiv_calculate /home/elmarco/src/qq= /crypto/ivgen-essiv.c:83:5 #2 0x561136d29af8 in qcrypto_ivgen_calculate /home/elmarco/src/qq/crypt= o/ivgen.c:72:12 #3 0x561136d07c8e in test_ivgen /home/elmarco/src/qq/tests/test-crypto-= ivgen.c:148:5 #4 0x7f77772c3b04 in test_case_run /home/elmarco/src/gnome/glib/builddi= r/../glib/gtestutils.c:2237 #5 0x7f77772c3ec4 in g_test_run_suite_internal /home/elmarco/src/gnome/= glib/builddir/../glib/gtestutils.c:2321 #6 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/= glib/builddir/../glib/gtestutils.c:2333 #7 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/= glib/builddir/../glib/gtestutils.c:2333 #8 0x7f77772c3f6d in g_test_run_suite_internal /home/elmarco/src/gnome/= glib/builddir/../glib/gtestutils.c:2333 #9 0x7f77772c4184 in g_test_run_suite /home/elmarco/src/gnome/glib/buil= ddir/../glib/gtestutils.c:2408 #10 0x7f77772c2e0d in g_test_run /home/elmarco/src/gnome/glib/builddir/= ../glib/gtestutils.c:1674 #11 0x561136d0799b in main /home/elmarco/src/qq/tests/test-crypto-ivgen= .c:173:12 #12 0x7f77756e6039 in __libc_start_main (/lib64/libc.so.6+0x21039) #13 0x561136c13d89 in _start (/home/elmarco/src/qq/build/tests/test-cry= pto-ivgen+0x6fd89) Address 0x7ffd8a1fe168 is located in stack of thread T0 at offset 40 in fra= me #0 0x561136d2a40f in qcrypto_ivgen_essiv_calculate /home/elmarco/src/qq= /crypto/ivgen-essiv.c:76 This frame has 1 object(s): [32, 40) 'sector.addr' <=3D=3D Memory access at offset 40 overflows thi= s variable HINT: this may be a false positive if your program uses some custom stack u= nwind mechanism or swapcontext (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow (/home/elmarco/src/qq/buil= d/tests/test-crypto-ivgen+0x110450) in __asan_memcpy Shadow bytes around the buggy address: 0x100031437bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =3D>0x100031437c20: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00[f3]f3 f3 0x100031437c30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100031437c70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb It looks like the rest of the code copes with ndata being larger than sizeof(sector), so limit the memcpy() range. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrange Reviewed-by: Thomas Huth Tested-by: Thomas Huth --- crypto/ivgen-essiv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/ivgen-essiv.c b/crypto/ivgen-essiv.c index cba20bde6c..ad4d926c19 100644 --- a/crypto/ivgen-essiv.c +++ b/crypto/ivgen-essiv.c @@ -79,7 +79,7 @@ static int qcrypto_ivgen_essiv_calculate(QCryptoIVGen *iv= gen, uint8_t *data =3D g_new(uint8_t, ndata); =20 sector =3D cpu_to_le64(sector); - memcpy(data, (uint8_t *)§or, ndata); + memcpy(data, (uint8_t *)§or, MIN(sizeof(sector), ndata)); if (sizeof(sector) < ndata) { memset(data + sizeof(sector), 0, ndata - sizeof(sector)); } --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082496516754.5495113832592; Thu, 4 Jan 2018 08:14:56 -0800 (PST) Received: from localhost ([::1]:47169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8AO-0006Af-DV for importer@patchew.org; Thu, 04 Jan 2018 11:14:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX84x-0000ix-87 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX84w-0005br-43 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13691) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX84v-0005b5-R1 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:14 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F7AF87633 for ; Thu, 4 Jan 2018 16:09:13 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id A56B76018D; Thu, 4 Jan 2018 16:09:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:18 +0100 Message-Id: <20180104160523.22995-14-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 16:09:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 13/18] qemu-config: fix leak in query-command-line-options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Direct leak of 160 byte(s) in 4 object(s) allocated from: #0 0x55ed7678cda8 in calloc (/home/elmarco/src/qq/build/x86_64-softmmu/= qemu-system-x86_64+0x797da8) #1 0x7f3f5e725f75 in g_malloc0 /home/elmarco/src/gnome/glib/builddir/..= /glib/gmem.c:124 #2 0x55ed778aa3a7 in query_option_descs /home/elmarco/src/qq/util/qemu-= config.c:60:16 #3 0x55ed778aa307 in get_drive_infolist /home/elmarco/src/qq/util/qemu-= config.c:140:19 #4 0x55ed778a9f40 in qmp_query_command_line_options /home/elmarco/src/q= q/util/qemu-config.c:254:36 #5 0x55ed76d4868c in qmp_marshal_query_command_line_options /home/elmar= co/src/qq/build/qmp-marshal.c:3078:14 #6 0x55ed77855dd5 in do_qmp_dispatch /home/elmarco/src/qq/qapi/qmp-disp= atch.c:104:5 #7 0x55ed778558cc in qmp_dispatch /home/elmarco/src/qq/qapi/qmp-dispatc= h.c:131:11 #8 0x55ed768b592f in handle_qmp_command /home/elmarco/src/qq/monitor.c:= 3840:11 #9 0x55ed7786ccfe in json_message_process_token /home/elmarco/src/qq/qo= bject/json-streamer.c:105:5 #10 0x55ed778fe37c in json_lexer_feed_char /home/elmarco/src/qq/qobject= /json-lexer.c:323:13 #11 0x55ed778fdde6 in json_lexer_feed /home/elmarco/src/qq/qobject/json= -lexer.c:373:15 #12 0x55ed7786cd83 in json_message_parser_feed /home/elmarco/src/qq/qob= ject/json-streamer.c:124:12 #13 0x55ed768b559e in monitor_qmp_read /home/elmarco/src/qq/monitor.c:3= 882:5 #14 0x55ed77714f29 in qemu_chr_be_write_impl /home/elmarco/src/qq/chard= ev/char.c:167:9 #15 0x55ed77714fde in qemu_chr_be_write /home/elmarco/src/qq/chardev/ch= ar.c:179:9 #16 0x55ed7772ffad in tcp_chr_read /home/elmarco/src/qq/chardev/char-so= cket.c:440:13 #17 0x55ed7777113b in qio_channel_fd_source_dispatch /home/elmarco/src/= qq/io/channel-watch.c:84:12 #18 0x7f3f5e71d90b in g_main_dispatch /home/elmarco/src/gnome/glib/buil= ddir/../glib/gmain.c:3182 #19 0x7f3f5e71e7ac in g_main_context_dispatch /home/elmarco/src/gnome/g= lib/builddir/../glib/gmain.c:3847 #20 0x55ed77886ffc in glib_pollfds_poll /home/elmarco/src/qq/util/main-= loop.c:214:9 #21 0x55ed778865fd in os_host_main_loop_wait /home/elmarco/src/qq/util/= main-loop.c:261:5 #22 0x55ed77886222 in main_loop_wait /home/elmarco/src/qq/util/main-loo= p.c:515:11 #23 0x55ed76d2a4df in main_loop /home/elmarco/src/qq/vl.c:1995:9 #24 0x55ed76d1cb4a in main /home/elmarco/src/qq/vl.c:4914:5 #25 0x7f3f555f6039 in __libc_start_main (/lib64/libc.so.6+0x21039) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Eric Blake --- util/qemu-config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/qemu-config.c b/util/qemu-config.c index 99b0e46fa3..029fec53a9 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -105,7 +105,8 @@ static void cleanup_infolist(CommandLineParameterInfoLi= st *head) if (!strcmp(pre_entry->value->name, cur->next->value->name)) { del_entry =3D cur->next; cur->next =3D cur->next->next; - g_free(del_entry); + del_entry->next =3D NULL; + qapi_free_CommandLineParameterInfoList(del_entry); break; } pre_entry =3D pre_entry->next; --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082684517441.59626085175853; Thu, 4 Jan 2018 08:18:04 -0800 (PST) Received: from localhost ([::1]:47310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8DQ-0001JC-41 for importer@patchew.org; Thu, 04 Jan 2018 11:18:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX852-0000nZ-9X for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX84y-0005dU-IW for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38365) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX84y-0005cr-C9 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:16 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A11B82578A for ; Thu, 4 Jan 2018 16:09:15 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id A479B60181; Thu, 4 Jan 2018 16:09:14 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:19 +0100 Message-Id: <20180104160523.22995-15-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 04 Jan 2018 16:09:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 14/18] tests: fix qmp-test leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, Markus Armbruster , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Direct leak of 913 byte(s) in 43 object(s) allocated from: #0 0x55880a15df60 in __interceptor_malloc (/home/elmarco/src/qq/build/t= ests/qmp-test+0x110f60) #1 0x7f3f20fd098f in _IO_vasprintf (/lib64/libc.so.6+0x8098f) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qmp-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qmp-test.c b/tests/qmp-test.c index c5a5c10b41..36feb2204b 100644 --- a/tests/qmp-test.c +++ b/tests/qmp-test.c @@ -271,7 +271,7 @@ static void add_query_tests(QmpSchema *schema) { SchemaInfoList *tail; SchemaInfo *si, *arg_type, *ret_type; - const char *test_name; + char *test_name; =20 /* Test the query-like commands */ for (tail =3D schema->list; tail; tail =3D tail->next) { @@ -297,6 +297,7 @@ static void add_query_tests(QmpSchema *schema) =20 test_name =3D g_strdup_printf("qmp/%s", si->name); qtest_add_data_func(test_name, si->name, test_query); + g_free(test_name); } } =20 --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515082774824133.45128308619155; Thu, 4 Jan 2018 08:19:34 -0800 (PST) Received: from localhost ([::1]:47313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Ev-0002eV-Uv for importer@patchew.org; Thu, 04 Jan 2018 11:19:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX855-0000pk-W0 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX852-0005gX-GY for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51095) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX852-0005fn-8H for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:20 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F72A5B2FD for ; Thu, 4 Jan 2018 16:09:19 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 304906017B; Thu, 4 Jan 2018 16:09:16 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:20 +0100 Message-Id: <20180104160523.22995-16-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 16:09:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 15/18] ucontext: annotate coroutine stack for ASAN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , famz@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It helps ASAN to detect more leaks on coroutine stacks, as found in the following patch. A similar work would need to be done for sigaltstack & windows fibers to have similar coverage. Since ucontext is preferred, I didn't bother checking the other coroutine implementations for now. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- include/qemu/compiler.h | 4 ++++ util/coroutine-ucontext.c | 46 +++++++++++++++++++++++++++++++++++++++++++= +++ 2 files changed, 50 insertions(+) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 340e5fdc09..5fcc4f7ec7 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -111,4 +111,8 @@ #define GCC_FMT_ATTR(n, m) #endif =20 +#ifndef __has_feature +#define __has_feature(x) 0 /* compatibility with non-clang compilers */ +#endif + #endif /* COMPILER_H */ diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index 6621f3f692..e78eae8766 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -31,6 +31,11 @@ #include #endif =20 +#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) +#define CONFIG_ASAN 1 +#include +#endif + typedef struct { Coroutine base; void *stack; @@ -59,11 +64,37 @@ union cc_arg { int i[2]; }; =20 +static void finish_switch_fiber(void *fake_stack_save) +{ +#ifdef CONFIG_ASAN + const void *bottom_old; + size_t size_old; + + __sanitizer_finish_switch_fiber(fake_stack_save, &bottom_old, &size_ol= d); + + if (!leader.stack) { + leader.stack =3D (void *)bottom_old; + leader.stack_size =3D size_old; + } +#endif +} + +static void start_switch_fiber(void **fake_stack_save, + const void *bottom, size_t size) +{ +#ifdef CONFIG_ASAN + __sanitizer_start_switch_fiber(fake_stack_save, bottom, size); +#endif +} + static void coroutine_trampoline(int i0, int i1) { union cc_arg arg; CoroutineUContext *self; Coroutine *co; + void *fake_stack_save =3D NULL; + + finish_switch_fiber(NULL); =20 arg.i[0] =3D i0; arg.i[1] =3D i1; @@ -72,9 +103,13 @@ static void coroutine_trampoline(int i0, int i1) =20 /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { + start_switch_fiber(&fake_stack_save, + leader.stack, leader.stack_size); siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } =20 + finish_switch_fiber(fake_stack_save); + while (true) { co->entry(co->entry_arg); qemu_coroutine_switch(co, co->caller, COROUTINE_TERMINATE); @@ -87,6 +122,7 @@ Coroutine *qemu_coroutine_new(void) ucontext_t old_uc, uc; sigjmp_buf old_env; union cc_arg arg =3D {0}; + void *fake_stack_save =3D NULL; =20 /* The ucontext functions preserve signal masks which incurs a * system call overhead. sigsetjmp(buf, 0)/siglongjmp() does not @@ -122,8 +158,12 @@ Coroutine *qemu_coroutine_new(void) =20 /* swapcontext() in, siglongjmp() back out */ if (!sigsetjmp(old_env, 0)) { + start_switch_fiber(&fake_stack_save, co->stack, co->stack_size); swapcontext(&old_uc, &uc); } + + finish_switch_fiber(fake_stack_save); + return &co->base; } =20 @@ -169,13 +209,19 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to= _, CoroutineUContext *from =3D DO_UPCAST(CoroutineUContext, base, from_); CoroutineUContext *to =3D DO_UPCAST(CoroutineUContext, base, to_); int ret; + void *fake_stack_save =3D NULL; =20 current =3D to_; =20 ret =3D sigsetjmp(from->env, 0); if (ret =3D=3D 0) { + start_switch_fiber(action =3D=3D COROUTINE_TERMINATE ? + NULL : &fake_stack_save, to->stack, to->stack_s= ize); siglongjmp(to->env, action); } + + finish_switch_fiber(fake_stack_save); + return ret; } =20 --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515083140382342.24843603970135; Thu, 4 Jan 2018 08:25:40 -0800 (PST) Received: from localhost ([::1]:48155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8Kp-0008N1-HP for importer@patchew.org; Thu, 04 Jan 2018 11:25:39 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX85K-00015d-1l for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX85G-0005uk-DU for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX85G-0005tp-72 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:34 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E1FB1A408C for ; Thu, 4 Jan 2018 16:09:33 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 613C1608F0; Thu, 4 Jan 2018 16:09:21 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:21 +0100 Message-Id: <20180104160523.22995-17-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 04 Jan 2018 16:09:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 16/18] tests: fix coroutine leak in /basic/entered X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , famz@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The coroutine is not finished by the time the test ends, resulting in ASAN warning: =3D=3D7005=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 312 byte(s) in 1 object(s) allocated from: #0 0x7fd35290fa38 in __interceptor_calloc (/lib64/libasan.so.4+0xdea38) #1 0x7fd3506c5f75 in g_malloc0 ../glib/gmem.c:124 #2 0x55994af03e47 in qemu_coroutine_new /home/elmarco/src/qemu/util/cor= outine-ucontext.c:144 #3 0x55994aefed99 in qemu_coroutine_create /home/elmarco/src/qemu/util/= qemu-coroutine.c:76 #4 0x55994ac1eb50 in verify_entered_step_1 /home/elmarco/src/qemu/tests= /test-coroutine.c:80 #5 0x55994af03c75 in coroutine_trampoline /home/elmarco/src/qemu/util/c= oroutine-ucontext.c:119 #6 0x7fd34ec02bef (/lib64/libc.so.6+0x50bef) Do not yield() to let the coroutine terminate. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi --- tests/test-coroutine.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index abd97c23c1..76c646107e 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -67,7 +67,6 @@ static void coroutine_fn verify_entered_step_2(void *opaq= ue) /* Once more to check it still works after yielding */ g_assert(qemu_coroutine_entered(caller)); g_assert(qemu_coroutine_entered(qemu_coroutine_self())); - qemu_coroutine_yield(); } =20 static void coroutine_fn verify_entered_step_1(void *opaque) --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151508287636120.1411736038998; Thu, 4 Jan 2018 08:21:16 -0800 (PST) Received: from localhost ([::1]:47449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8GZ-0004BJ-DW for importer@patchew.org; Thu, 04 Jan 2018 11:21:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX85K-00015i-2c for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX85I-0005xG-Pe for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45633) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX85I-0005wg-J2 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:36 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1A855B2F9 for ; Thu, 4 Jan 2018 16:09:35 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04F39608EE; Thu, 4 Jan 2018 16:09:34 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:22 +0100 Message-Id: <20180104160523.22995-18-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 04 Jan 2018 16:09:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 17/18] mips: fix potential fopen(NULL,...) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, famz@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Spotted thanks to ASAN. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/nvram/ds1225y.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/nvram/ds1225y.c b/hw/nvram/ds1225y.c index 57d5ab2154..ad7345f288 100644 --- a/hw/nvram/ds1225y.c +++ b/hw/nvram/ds1225y.c @@ -80,7 +80,7 @@ static int nvram_post_load(void *opaque, int version_id) } =20 /* Write back nvram contents */ - s->file =3D fopen(s->filename, "wb"); + s->file =3D s->filename ? fopen(s->filename, "wb") : NULL; if (s->file) { /* Write back contents, as 'wb' mode cleaned the file */ if (fwrite(s->contents, s->chip_size, 1, s->file) !=3D 1) { @@ -126,7 +126,7 @@ static int nvram_sysbus_initfn(SysBusDevice *dev) sysbus_init_mmio(dev, &s->iomem); =20 /* Read current file */ - file =3D fopen(s->filename, "rb"); + file =3D s->filename ? fopen(s->filename, "rb") : NULL; if (file) { /* Read nvram contents */ if (fread(s->contents, s->chip_size, 1, file) !=3D 1) { --=20 2.15.1.355.g36791d7216 From nobody Tue Oct 28 01:57:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515083036215527.1877954684982; Thu, 4 Jan 2018 08:23:56 -0800 (PST) Received: from localhost ([::1]:47669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8J9-0006Vt-CK for importer@patchew.org; Thu, 04 Jan 2018 11:23:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX85N-00019R-Cl for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eX85M-00060J-14 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 11:09:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45880) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eX85L-0005zR-Or; Thu, 04 Jan 2018 11:09:39 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4317C00F708; Thu, 4 Jan 2018 16:09:38 +0000 (UTC) Received: from localhost (ovpn-112-61.ams2.redhat.com [10.36.112.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BAAE60473; Thu, 4 Jan 2018 16:09:37 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Thu, 4 Jan 2018 17:05:23 +0100 Message-Id: <20180104160523.22995-19-marcandre.lureau@redhat.com> In-Reply-To: <20180104160523.22995-1-marcandre.lureau@redhat.com> References: <20180104160523.22995-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 04 Jan 2018 16:09:39 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 18/18] disas/s390: fix global-buffer-overflow X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, Alexander Graf , "open list:S390 target" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Spotted thanks to ASAN: =3D=3D25226=3D=3DERROR: AddressSanitizer: global-buffer-overflow on address= 0x556715a1f120 at pc 0x556714b6f6b1 bp 0x7ffcdfac1360 sp 0x7ffcdfac1350 READ of size 1 at 0x556715a1f120 thread T0 #0 0x556714b6f6b0 in init_disasm /home/elmarco/src/qemu/disas/s390.c:219 #1 0x556714b6fa6a in print_insn_s390 /home/elmarco/src/qemu/disas/s390.= c:294 #2 0x55671484d031 in monitor_disas /home/elmarco/src/qemu/disas.c:635 #3 0x556714862ec0 in memory_dump /home/elmarco/src/qemu/monitor.c:1324 #4 0x55671486342a in hmp_memory_dump /home/elmarco/src/qemu/monitor.c:1= 418 #5 0x5567148670be in handle_hmp_command /home/elmarco/src/qemu/monitor.= c:3109 #6 0x5567148674ed in qmp_human_monitor_command /home/elmarco/src/qemu/m= onitor.c:613 #7 0x556714b00918 in qmp_marshal_human_monitor_command /home/elmarco/sr= c/qemu/build/qmp-marshal.c:1704 #8 0x556715138a3e in do_qmp_dispatch /home/elmarco/src/qemu/qapi/qmp-di= spatch.c:104 #9 0x556715138f83 in qmp_dispatch /home/elmarco/src/qemu/qapi/qmp-dispa= tch.c:131 #10 0x55671485cf88 in handle_qmp_command /home/elmarco/src/qemu/monitor= .c:3839 #11 0x55671514e80b in json_message_process_token /home/elmarco/src/qemu= /qobject/json-streamer.c:105 #12 0x5567151bf2dc in json_lexer_feed_char /home/elmarco/src/qemu/qobje= ct/json-lexer.c:323 #13 0x5567151bf827 in json_lexer_feed /home/elmarco/src/qemu/qobject/js= on-lexer.c:373 #14 0x55671514ee62 in json_message_parser_feed /home/elmarco/src/qemu/q= object/json-streamer.c:124 #15 0x556714854b1f in monitor_qmp_read /home/elmarco/src/qemu/monitor.c= :3881 #16 0x556715045440 in qemu_chr_be_write_impl /home/elmarco/src/qemu/cha= rdev/char.c:172 #17 0x556715047184 in qemu_chr_be_write /home/elmarco/src/qemu/chardev/= char.c:184 #18 0x55671505a8e6 in tcp_chr_read /home/elmarco/src/qemu/chardev/char-= socket.c:440 #19 0x5567150943c3 in qio_channel_fd_source_dispatch /home/elmarco/src/= qemu/io/channel-watch.c:84 #20 0x7fb90292b90b in g_main_dispatch ../glib/gmain.c:3182 #21 0x7fb90292c7ac in g_main_context_dispatch ../glib/gmain.c:3847 #22 0x556715162eca in glib_pollfds_poll /home/elmarco/src/qemu/util/mai= n-loop.c:214 #23 0x556715163001 in os_host_main_loop_wait /home/elmarco/src/qemu/uti= l/main-loop.c:261 #24 0x5567151631fa in main_loop_wait /home/elmarco/src/qemu/util/main-l= oop.c:515 #25 0x556714ad6d3b in main_loop /home/elmarco/src/qemu/vl.c:1950 #26 0x556714ade329 in main /home/elmarco/src/qemu/vl.c:4865 #27 0x7fb8fe5c9009 in __libc_start_main (/lib64/libc.so.6+0x21009) #28 0x5567147af4d9 in _start (/home/elmarco/src/qemu/build/s390x-softmm= u/qemu-system-s390x+0xf674d9) 0x556715a1f120 is located 32 bytes to the left of global variable 'char_hci= _type_info' defined in '/home/elmarco/src/qemu/hw/bt/hci-csr.c:493:23' (0x5= 56715a1f140) of size 104 0x556715a1f120 is located 8 bytes to the right of global variable 's390_opc= odes' defined in '/home/elmarco/src/qemu/disas/s390.c:860:33' (0x556715a152= 80) of size 40600 This fix is based on Andreas Arnez upstream commit: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;a=3Dcommitdiff;h= =3D9ace48f3d7d80ce09c5df60cccb433470410b11b 2014-08-19 Andreas Arnez * s390-dis.c (init_disasm): Simplify initialization of opc_index[]. This also fixes an access after the last element of s390_opcodes[]. Signed-off-by: Marc-Andr=C3=A9 Lureau --- disas/s390.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/disas/s390.c b/disas/s390.c index 1f167d2eaa..6393860239 100644 --- a/disas/s390.c +++ b/disas/s390.c @@ -207,18 +207,14 @@ static int opc_index[256]; static void init_disasm (struct disassemble_info *info) { - const struct s390_opcode *opcode; - const struct s390_opcode *opcode_end; + int i; =20 memset (opc_index, 0, sizeof (opc_index)); - opcode_end =3D s390_opcodes + s390_num_opcodes; - for (opcode =3D s390_opcodes; opcode < opcode_end; opcode++) - { - opc_index[(int) opcode->opcode[0]] =3D opcode - s390_opcodes; - while ((opcode < opcode_end) && - (opcode[1].opcode[0] =3D=3D opcode->opcode[0])) - opcode++; - } + + /* Reverse order, such that each opc_index ends up pointing to the + first matching entry instead of the last. */ + for (i =3D s390_num_opcodes; i--; ) + opc_index[s390_opcodes[i].opcode[0]] =3D i; =20 #ifdef QEMU_DISABLE switch (info->mach) --=20 2.15.1.355.g36791d7216