Patchwork [12/19] linux-user: Allow NULL value pointer in setxattr and getxattr

login
register
mail settings
Submitter riku.voipio@linaro.org
Date Feb. 3, 2012, 2:49 p.m.
Message ID <e3c33ec6b07dc4d0503cb43b2114be47fc344d36.1328280144.git.riku.voipio@linaro.org>
Download mbox | patch
Permalink /patch/139403/
State New
Headers show

Comments

riku.voipio@linaro.org - Feb. 3, 2012, 2:49 p.m.
From: Peter Maydell <peter.maydell@linaro.org>

It's valid to pass a NULL value pointer to setxattr, so don't
fail this case EFAULT.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 06b19e0..0a78a18 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7809,11 +7809,17 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_setxattr:
         {
-            void *p, *n, *v;
+            void *p, *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_READ, arg3, arg4, 1);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
-            v = lock_user(VERIFY_READ, arg3, arg4, 1);
-            if (p && n && v) {
+            if (p && n) {
                 ret = get_errno(setxattr(p, n, v, arg4, arg5));
             } else {
                 ret = -TARGET_EFAULT;
@@ -7825,11 +7831,17 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
     case TARGET_NR_getxattr:
         {
-            void *p, *n, *v;
+            void *p, *n, *v = 0;
+            if (arg3) {
+                v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
+                if (!v) {
+                    ret = -TARGET_EFAULT;
+                    break;
+                }
+            }
             p = lock_user_string(arg1);
             n = lock_user_string(arg2);
-            v = lock_user(VERIFY_WRITE, arg3, arg4, 0);
-            if (p && n && v) {
+            if (p && n) {
                 ret = get_errno(getxattr(p, n, v, arg4));
             } else {
                 ret = -TARGET_EFAULT;