From: Andreas Schwab <schwab@suse.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length
Date: Tue, 11 Sep 2018 14:03:04 +0200 [thread overview]
Message-ID: <mvmd0tkckcn.fsf@suse.de> (raw)
A zero-length read still needs to do the usual checks, thus it may return
errors like EBADF.
Signed-off-by: Andreas Schwab <schwab@suse.de>
---
linux-user/syscall.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 643b8833de..202d3c287d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7930,18 +7930,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
ret = 0; /* avoid warning */
break;
case TARGET_NR_read:
- if (arg3 == 0)
- ret = 0;
- else {
- if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
- goto efault;
- ret = get_errno(safe_read(arg1, p, arg3));
- if (ret >= 0 &&
- fd_trans_host_to_target_data(arg1)) {
- ret = fd_trans_host_to_target_data(arg1)(p, ret);
- }
- unlock_user(p, arg2, ret);
+ if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+ goto efault;
+ ret = get_errno(safe_read(arg1, p, arg3));
+ if (ret >= 0 &&
+ fd_trans_host_to_target_data(arg1)) {
+ ret = fd_trans_host_to_target_data(arg1)(p, ret);
}
+ unlock_user(p, arg2, ret);
break;
case TARGET_NR_write:
if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
--
2.18.0
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
next reply other threads:[~2018-09-11 12:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-11 12:03 Andreas Schwab [this message]
2018-09-12 17:22 ` [Qemu-devel] [PATCH] linux-user: don't short-circuit read with zero length Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
2019-03-05 16:45 Andreas Schwab
2019-03-05 17:31 ` Laurent Vivier
2019-03-06 13:11 ` Laurent Vivier
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=mvmd0tkckcn.fsf@suse.de \
--to=schwab@suse.de \
--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 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.