qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Jingqi Liu <jingqi.liu@intel.com>
Subject: Re: [PATCH] softmmu/physmem.c: Check return value from realpath()
Date: Fri, 13 Aug 2021 14:29:00 +0200	[thread overview]
Message-ID: <f9232061-b9d3-c94e-81fa-d59330be4400@redhat.com> (raw)
In-Reply-To: <20210812151525.31456-1-peter.maydell@linaro.org>

On 12/08/21 17:15, Peter Maydell wrote:
> The realpath() function can return NULL on error, so we need to check
> for it to avoid crashing when we try to strstr() into it.
> This can happen if we run out of memory, or if /sys/ is not mounted,
> among other situations.
> 
> Fixes: Coverity 1459913, 1460474
> Fixes: ce317be98db0 ("exec: fetch the alignment of Linux devdax pmem character device nodes")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   softmmu/physmem.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index c47cb6da2e4..eb0595d57c4 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -1451,6 +1451,9 @@ static int64_t get_file_align(int fd)
>           path = g_strdup_printf("/sys/dev/char/%d:%d",
>                       major(st.st_rdev), minor(st.st_rdev));
>           rpath = realpath(path, NULL);
> +        if (!rpath) {
> +            return -errno;
> +        }
>   
>           rc = daxctl_new(&ctx);
>           if (rc) {
> 

Queued, thanks.

Paolo



      parent reply	other threads:[~2021-08-13 12:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 15:15 [PATCH] softmmu/physmem.c: Check return value from realpath() Peter Maydell
2021-08-13  7:24 ` Liu, Jingqi
2021-08-13 12:29 ` Paolo Bonzini [this message]

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=f9232061-b9d3-c94e-81fa-d59330be4400@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=jingqi.liu@intel.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: 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).