diff mbox series

[49/66] bsd-user: sendto/recvfrom need + 1 too for addrlen

Message ID 20260515-misc-2026q2-v1-49-5438ca41b27a@bsdimp.com
State New
Headers show
Series bsd-user: Upstream most of the remaining system calls | expand

Commit Message

Warner Losh May 15, 2026, 9:19 p.m. UTC
Since we adjust the length of the addrlen by upto 1 to cope with the
off-by-one errors that plague unix domain sockets, we need to add 1 to
the length we alloc off the stack to account for this. It's not common
to sendto/recvfrom a UNIX domain socket, but it is possible.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 bsd-user/bsd-socket.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
index 578cc3959d..d85dec59c0 100644
--- a/bsd-user/bsd-socket.h
+++ b/bsd-user/bsd-socket.h
@@ -198,7 +198,7 @@  static inline abi_long do_bsd_sendto(int fd, abi_ulong msg, size_t len,
         host_msg = NULL;
     }
     if (target_addr) {
-        saddr = alloca(addrlen);
+        saddr = alloca(addrlen + 1);
         ret = target_to_host_sockaddr(saddr, target_addr, addrlen);
         if (is_error(ret)) {
             unlock_user(host_msg, msg, 0);
@@ -235,7 +235,7 @@  static inline abi_long do_bsd_recvfrom(int fd, abi_ulong msg, size_t len,
             ret = -TARGET_EINVAL;
             goto fail;
         }
-        saddr = alloca(addrlen);
+        saddr = alloca(addrlen + 1);
         ret = get_errno(safe_recvfrom(fd, host_msg, len, flags, saddr,
                     &addrlen));
     } else {