Skip to content

Commit

Permalink
linux-user: don't short-circuit read with zero length
Browse files Browse the repository at this point in the history
A zero-length read still needs to do the usual checks, thus it may return
errors like EBADF.  This makes the read syscall emulation consistent with
the pread64 syscall emulation.

Signed-off-by: Andreas Schwab <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Laurent Vivier <[email protected]>
  • Loading branch information
andreas-schwab authored and vivier committed Mar 7, 2019
1 parent 14c8a3a commit ba584f1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -7009,8 +7009,8 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
_exit(arg1);
return 0; /* avoid warning */
case TARGET_NR_read:
if (arg3 == 0) {
return 0;
if (arg2 == 0 && arg3 == 0) {
return get_errno(safe_read(arg1, 0, 0));
} else {
if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
return -TARGET_EFAULT;
Expand Down

0 comments on commit ba584f1

Please sign in to comment.