From: Peter Maydell <peter.maydell@linaro.org>
To: Stefan Weil <sw@weilnetz.de>
Cc: QEMU Trivial <qemu-trivial@nongnu.org>,
Riku Voipio <riku.voipio@iki.fi>,
QEMU Developer <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] linux-user: Add missing check for return value of lock_user
Date: Sun, 15 Mar 2015 11:15:53 +0000 [thread overview]
Message-ID: <CAFEAcA8GaCcB0ga4EhLL9ePYV3xrixjgjr7CiRBQuR5NEJjgRA@mail.gmail.com> (raw)
In-Reply-To: <1426345935-7721-1-git-send-email-sw@weilnetz.de>
On 14 March 2015 at 15:12, Stefan Weil <sw@weilnetz.de> wrote:
> This fixes a warning from Coverity:
> "Dereference null return value (NULL_RETURNS)"
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
> linux-user/flatload.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/flatload.c b/linux-user/flatload.c
> index 566a7a8..56ac790 100644
> --- a/linux-user/flatload.c
> +++ b/linux-user/flatload.c
> @@ -97,11 +97,13 @@ static int target_pread(int fd, abi_ulong ptr, abi_ulong len,
> abi_ulong offset)
> {
> void *buf;
> - int ret;
> + int ret = -TARGET_EFAULT;
The return value for this function should be a host errno,
not a target errno, I think. (If you track back upwards
then eventually main.c calls loader_exec() and treats the
return value as a host errno.) This seems like the right
thing given that these loader functions are all pre-run
setup, and are not involved in emulation of guest syscalls.
>
> buf = lock_user(VERIFY_WRITE, ptr, len, 0);
> - ret = pread(fd, buf, len, offset);
> - unlock_user(buf, ptr, len);
> + if (buf) {
> + ret = pread(fd, buf, len, offset);
A different bug, but if ret here indicates that pread()
failed we should be returning -errno.
> + unlock_user(buf, ptr, len);
> + }
> return ret;
> }
-- PMM
next prev parent reply other threads:[~2015-03-15 11:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-14 15:12 [Qemu-devel] [PATCH] linux-user: Add missing check for return value of lock_user Stefan Weil
2015-03-15 11:15 ` Peter Maydell [this message]
2015-10-19 14:28 ` Paolo Bonzini
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=CAFEAcA8GaCcB0ga4EhLL9ePYV3xrixjgjr7CiRBQuR5NEJjgRA@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=sw@weilnetz.de \
/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).