Skip to contentSkip to conversation

fix read() and acct() on NULL arguments

PATCH Applied Riku Voipio 2 participants 2 messages Jan 19, 2009 – Jan 30, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix read() and acct() on NULL arguments

Returning efault in these cases is not correct. Originally proposed by Thayne Harbaugh in 2007:

http://www.mail-archive.com/[email protected]/msg14658.html

---
 linux-user/syscall.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +16 -8
index 4eb003a..ab81b3a 100644
@@ -3713,10 +3713,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
-            goto efault;
-        ret = get_errno(read(arg1, p, arg3));
-        unlock_user(p, arg2, ret);
+        if (arg3 == 0)
+            ret = 0;
+        else {
+            if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+                goto efault;
+            ret = get_errno(read(arg1, p, arg3));
+            unlock_user(p, arg2, ret);
+        }
         break;
     case TARGET_NR_write:
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
@@ -4217,10 +4221,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         goto unimplemented;
 #endif
     case TARGET_NR_acct:
-        if (!(p = lock_user_string(arg1)))
-            goto efault;
-        ret = get_errno(acct(path(p)));
-        unlock_user(p, arg1, 0);
+        if (arg1 == 0) {
+            ret = get_errno(acct(NULL));
+        } else {
+            if (!(p = lock_user_string(arg1)))
+                goto efault;
+            ret = get_errno(acct(path(p)));
+            unlock_user(p, arg1, 0);
+        }
         break;
 #ifdef TARGET_NR_umount2 /* not on alpha */
     case TARGET_NR_umount2:
Signature · 5 lines
1.5.6.5


-- 
"rm -rf" only sounds scary if you don't have backups
#1 lore raw
Quoted 6 lines · Riku Voipio

Returning efault in these cases is not correct. Originally proposed by Thayne Harbaugh in 2007:

http://www.mail-archive.com/[email protected]/msg14658.html

Thanks, applied.

Quoted 55 lines
---
 linux-user/syscall.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)
linux-user/syscall.c +16 -8
index 4eb003a..ab81b3a 100644
@@ -3713,10 +3713,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         ret = 0; /* avoid warning */
         break;
     case TARGET_NR_read:
-        if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
-            goto efault;
-        ret = get_errno(read(arg1, p, arg3));
-        unlock_user(p, arg2, ret);
+        if (arg3 == 0)
+            ret = 0;
+        else {
+            if (!(p = lock_user(VERIFY_WRITE, arg2, arg3, 0)))
+                goto efault;
+            ret = get_errno(read(arg1, p, arg3));
+            unlock_user(p, arg2, ret);
+        }
         break;
     case TARGET_NR_write:
         if (!(p = lock_user(VERIFY_READ, arg2, arg3, 1)))
@@ -4217,10 +4221,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         goto unimplemented;
 #endif
     case TARGET_NR_acct:
-        if (!(p = lock_user_string(arg1)))
-            goto efault;
-        ret = get_errno(acct(path(p)));
-        unlock_user(p, arg1, 0);
+        if (arg1 == 0) {
+            ret = get_errno(acct(NULL));
+        } else {
+            if (!(p = lock_user_string(arg1)))
+                goto efault;
+            ret = get_errno(acct(path(p)));
+            unlock_user(p, arg1, 0);
+        }
         break;
 #ifdef TARGET_NR_umount2 /* not on alpha */
     case TARGET_NR_umount2:
Signature · 5 lines
1.5.6.5


-- 
"rm -rf" only sounds scary if you don't have backups
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net