OSDN Git Service

linux-user: Fix error handling in flatload.c target_pread()
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 12 Jul 2016 12:02:15 +0000 (13:02 +0100)
committerRiku Voipio <riku.voipio@linaro.org>
Wed, 21 Sep 2016 11:27:19 +0000 (14:27 +0300)
The flatload.c target_pread() function is supposed to return
0 on success or negative host errnos; however it wasn't
checking lock_user() for failure or returning the errno from
the pread() call. Fix these problems (the first of which is
noted by Coverity).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
linux-user/flatload.c

index 42d1079..a35a560 100644 (file)
@@ -95,7 +95,13 @@ static int target_pread(int fd, abi_ulong ptr, abi_ulong len,
     int ret;
 
     buf = lock_user(VERIFY_WRITE, ptr, len, 0);
+    if (!buf) {
+        return -EFAULT;
+    }
     ret = pread(fd, buf, len, offset);
+    if (ret < 0) {
+        ret = -errno;
+    }
     unlock_user(buf, ptr, len);
     return ret;
 }