Skip to contentSkip to conversation

linux-user: don't short-circuit read with zero length

PATCH Applied Andreas Schwab 2 participants 3 messages Mar 5, 2019 – Mar 6, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: don't short-circuit read with zero length

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.

---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
index ff912e89e1..7fac8e318f 100644
@@ -7047,8 +7047,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;
Signature · 6 lines
2.21.0

-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reviewed-by on v1 1/1
#1 lore raw

Le 05/03/2019 à 17:45, Andreas Schwab a écrit :

Quoted 15 lines

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.

---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +0 -0
index ff912e89e1..7fac8e318f 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 7054

Quoted 10 lines
linux-user/syscall.c +2 -2
@@ -7047,8 +7047,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;
#2 lore raw
In reply to Andreas Schwab
Quoted 15 lines · Andreas Schwab

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.

---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +0 -0
index ff912e89e1..7fac8e318f 100644

linux-user/syscall.c static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, · line 7054

Quoted 10 lines
linux-user/syscall.c +2 -2
@@ -7047,8 +7047,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;

Applied to my linux-user branch.

Thanks,
Laurent