qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kostiantyn Kostiuk <kkostiuk@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL v2 1/9] qga: Fix ubsan warning
Date: Mon,  1 Sep 2025 14:24:05 +0300	[thread overview]
Message-ID: <20250901112413.114314-2-kkostiuk@redhat.com> (raw)
In-Reply-To: <20250901112413.114314-1-kkostiuk@redhat.com>

From: Thomas Huth <thuth@redhat.com>

When compiling QEMU with --enable-ubsan there is a undefined behavior
warning when running "make check":

 .../qga/commands-linux.c:452:15: runtime error: applying non-zero offset 5 to null pointer
 #0 0x55ea7b89450c in build_guest_fsinfo_for_pci_dev ..../qga/commands-linux.c:452:15

Fix it by avoiding the additional pointer variable here and use an
"offset" integer variable instead.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250730072709.27077-1-thuth@redhat.com
Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
---
 qga/commands-linux.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 9dc0c82503..4a09ddc760 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -400,10 +400,10 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
                                            Error **errp)
 {
     unsigned int pci[4], host, hosts[8], tgt[3];
-    int i, nhosts = 0, pcilen;
+    int i, offset, nhosts = 0, pcilen;
     GuestPCIAddress *pciaddr = disk->pci_controller;
     bool has_ata = false, has_host = false, has_tgt = false;
-    char *p, *q, *driver = NULL;
+    char *p, *driver = NULL;
     bool ret = false;
 
     p = strstr(syspath, "/devices/pci");
@@ -445,13 +445,13 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
 
     p = strstr(syspath, "/ata");
     if (p) {
-        q = p + 4;
+        offset = 4;
         has_ata = true;
     } else {
         p = strstr(syspath, "/host");
-        q = p + 5;
+        offset = 5;
     }
-    if (p && sscanf(q, "%u", &host) == 1) {
+    if (p && sscanf(p + offset, "%u", &host) == 1) {
         has_host = true;
         nhosts = build_hosts(syspath, p, has_ata, hosts,
                              ARRAY_SIZE(hosts), errp);
-- 
2.50.1



  reply	other threads:[~2025-09-01 11:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01 11:24 [PULL v2 0/9] Misc QGA fixes for 2025-08-29 Kostiantyn Kostiuk
2025-09-01 11:24 ` Kostiantyn Kostiuk [this message]
2025-09-01 11:24 ` [PULL v2 2/9] qga: fix potentially not initialized nr_volumes in qga_vss_fsfreeze() Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 3/9] qga-vss: Replace asserts with condition and report error Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 4/9] qga-vss: Remove unused dependencies Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 5/9] qga: Fix channel initialization check in run_agent_once Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 6/9] qga: ignore channel_init() fail if 'retry_path' is set Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 7/9] qga-vss: Write hex value of error in log Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 8/9] qga/installer: Remove QGA VSS if QGA installation failed Kostiantyn Kostiuk
2025-09-01 11:24 ` [PULL v2 9/9] qga: Fix truncated output handling in guest-exec status reporting Kostiantyn Kostiuk
2025-09-02 13:47 ` [PULL v2 0/9] Misc QGA fixes for 2025-08-29 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250901112413.114314-2-kkostiuk@redhat.com \
    --to=kkostiuk@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).