Skip to content

Commit

Permalink
linux-user: do_msgrcv: don't leak host_mb upon TARGET_EFAULT failure
Browse files Browse the repository at this point in the history
Also, use g_malloc to avoid NULL-deref upon OOM.

Signed-off-by: Jim Meyering <[email protected]>
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
Jim Meyering authored and Anthony Liguori committed Aug 22, 2012
1 parent 4144f12 commit 0d07fe4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2848,7 +2848,7 @@ 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 = malloc(msgsz+sizeof(long));
host_mb = g_malloc(msgsz+sizeof(long));
ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg));

if (ret > 0) {
Expand All @@ -2863,11 +2863,11 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
}

target_mb->mtype = tswapal(host_mb->mtype);
free(host_mb);

end:
if (target_mb)
unlock_user_struct(target_mb, msgp, 1);
g_free(host_mb);
return ret;
}

Expand Down

0 comments on commit 0d07fe4

Please sign in to comment.