[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 6/6] linux-user: Fix error handling in target_to_hos
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 6/6] linux-user: Fix error handling in target_to_host_semarray() |
Date: |
Wed, 19 Feb 2014 12:35:29 +0200 |
From: Peter Maydell <address@hidden>
Fix two issues in error handling in target_to_host_semarray():
* don't leak the host_array buffer if lock_user fails
* return an error if malloc() fails
v2: added missing * -Riku Voipio
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/syscall.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8f5a58e..1407b7a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2430,10 +2430,15 @@ static inline abi_long target_to_host_semarray(int
semid, unsigned short **host_
nsems = semid_ds.sem_nsems;
*host_array = malloc(nsems*sizeof(unsigned short));
+ if (!*host_array) {
+ return -TARGET_ENOMEM;
+ }
array = lock_user(VERIFY_READ, target_addr,
nsems*sizeof(unsigned short), 1);
- if (!array)
+ if (!array) {
+ free(*host_array);
return -TARGET_EFAULT;
+ }
for(i=0; i<nsems; i++) {
__get_user((*host_array)[i], &array[i]);
--
1.8.1.2
- [Qemu-devel] [PULL 0/6] linux-user updates, riku . voipio, 2014/02/19
- [Qemu-devel] [PATCH 3/6] linux-user/signal.c: Don't pass sigaction uninitialised sa_flags, riku . voipio, 2014/02/19
- [Qemu-devel] [PATCH 4/6] linux-user: Fix error handling in lock_iovec(), riku . voipio, 2014/02/19
- [Qemu-devel] [PATCH 5/6] linux-user: Implement BLKPG ioctl, riku . voipio, 2014/02/19
- [Qemu-devel] [PATCH 2/6] linux-user/elfload.c: Avoid calling g_free() on uninitialized data, riku . voipio, 2014/02/19
- [Qemu-devel] [PATCH 6/6] linux-user: Fix error handling in target_to_host_semarray(),
riku . voipio <=
- [Qemu-devel] [PATCH 1/6] linux-user: sync syscall numbers upto 3.13, riku . voipio, 2014/02/19
- Re: [Qemu-devel] [PULL 0/6] linux-user updates, Peter Maydell, 2014/02/21