]> Git Repo - qemu.git/commitdiff
linux-user: Use g_try_malloc() in do_msgrcv()
authorPeter Maydell <[email protected]>
Fri, 20 May 2016 18:00:57 +0000 (19:00 +0100)
committerRiku Voipio <[email protected]>
Fri, 27 May 2016 11:50:39 +0000 (14:50 +0300)
In do_msgrcv() we want to allocate a message buffer, whose size
is passed to us by the guest. That means we could legitimately
fail, so use g_try_malloc() and handle the error case, in the same
way that do_msgsnd() does.

Signed-off-by: Peter Maydell <[email protected]>
Signed-off-by: Riku Voipio <[email protected]>
linux-user/syscall.c

index cec5b80331701467c06159f6c7d1757da02622d3..40e8742924b8a37b98056067c82ab25de31216e1 100644 (file)
@@ -3167,7 +3167,11 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0))
         return -TARGET_EFAULT;
 
-    host_mb = g_malloc(msgsz+sizeof(long));
+    host_mb = g_try_malloc(msgsz + sizeof(long));
+    if (!host_mb) {
+        ret = -TARGET_ENOMEM;
+        goto end;
+    }
     ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
 
     if (ret > 0) {
This page took 0.048839 seconds and 4 git commands to generate.