From 4a1e6bce2308b720d79d5ea0a3d24501c89bd80c Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Fri, 26 Mar 2021 22:11:16 -0400 Subject: linux-user: allow NULL msg in recvfrom The kernel allows a NULL msg in recvfrom so that he size of the next message may be queried before allocating a correctly sized buffer. This change allows the syscall translator to pass along the NULL msg pointer instead of returning early with EFAULT. Signed-off-by: Zach Reizner Reviewed-by: Laurent Vivier Message-Id: Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'linux-user') diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1e508576c7..294779c86f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3679,9 +3679,14 @@ static abi_long do_recvfrom(int fd, abi_ulong msg, size_t len, int flags, void *host_msg; abi_long ret; - host_msg = lock_user(VERIFY_WRITE, msg, len, 0); - if (!host_msg) - return -TARGET_EFAULT; + if (!msg) { + host_msg = NULL; + } else { + host_msg = lock_user(VERIFY_WRITE, msg, len, 0); + if (!host_msg) { + return -TARGET_EFAULT; + } + } if (target_addr) { if (get_user_u32(addrlen, target_addrlen)) { ret = -TARGET_EFAULT; -- cgit v1.2.3