qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PULL 12/26] linux-user: Fix error handling in flatload.c t


From: riku . voipio
Subject: [Qemu-devel] [PULL 12/26] linux-user: Fix error handling in flatload.c target_pread()
Date: Thu, 22 Sep 2016 15:13:32 +0300

From: Peter Maydell <address@hidden>

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 <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
 linux-user/flatload.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/linux-user/flatload.c b/linux-user/flatload.c
index 42d1079..a35a560 100644
--- a/linux-user/flatload.c
+++ b/linux-user/flatload.c
@@ -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;
 }
-- 
2.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]