All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org, Michael Roth <michael.roth@amd.com>,
	Kostiantyn Kostiuk <kkostiuk@redhat.com>,
	qemu-trivial@nongnu.org
Subject: Re: [PATCH] qga: Fix ubsan warning
Date: Mon, 28 Jul 2025 18:53:23 +0100	[thread overview]
Message-ID: <aIe5E5NaMCGhoiLZ@redhat.com> (raw)
In-Reply-To: <20250728173016.314460-1-thuth@redhat.com>

On Mon, Jul 28, 2025 at 07:30:16PM +0200, Thomas Huth wrote:
> 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
> 
> Add a check to avoid incrementing the NULL pointer here.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>  qga/commands-linux.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/qga/commands-linux.c b/qga/commands-linux.c
> index 9e8a934b9a6..caf7c3ca22b 100644
> --- a/qga/commands-linux.c
> +++ b/qga/commands-linux.c
> @@ -449,7 +449,9 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,
>          has_ata = true;
>      } else {
>          p = strstr(syspath, "/host");
> -        q = p + 5;
> +        if (p) {
> +            q = p + 5;
> +        }
>      }
>      if (p && sscanf(q, "%u", &host) == 1) {

q is always non-NULL if p is non-NULL, so this is safe, but I would be more
happy with this changing to 'q && sscanf' to eliminate the indirection.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2025-07-28 17:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28 17:30 [PATCH] qga: Fix ubsan warning Thomas Huth
2025-07-28 17:53 ` Daniel P. Berrangé [this message]
2025-07-29  6:02   ` Thomas Huth
2025-07-29  6:23     ` Daniel P. Berrangé
2025-07-29  6:58     ` Kostiantyn Kostiuk

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=aIe5E5NaMCGhoiLZ@redhat.com \
    --to=berrange@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=thuth@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.