From 255f72ff7dbb163f3871ef043626114831fb4e42 Mon Sep 17 00:00:00 2001 From: Oleksii Moisieiev Date: Thu, 11 Jan 2024 12:06:19 +0200 Subject: [PATCH] lib/posix-socket: Fix raddr set call in uk_sys_accept uk_socket_evd_raddr_set receives *addr_len as an input parameter, which means that NullPointerException is generated when addr_len is NULL. Also, al->evd structure is present only when CONFIG_LIBPOSIX_SOCKET_EVENTS enabled so wrapping usages under #ifdef. Signed-off-by: Oleksii Moisieiev Reviewed-by: Michalis Pappas Approved-by: Simon Kuenzer GitHub-Closes: #1269 --- lib/posix-socket/socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/posix-socket/socket.c b/lib/posix-socket/socket.c index ea64b626f8..510ce89795 100644 --- a/lib/posix-socket/socket.c +++ b/lib/posix-socket/socket.c @@ -341,9 +341,11 @@ int uk_sys_accept(const struct uk_file *sock, int blocking, _socket_init(al, n->driver, new_data); al_listener = __containerof(sock, struct socket_alloc, f); +#if CONFIG_LIBPOSIX_SOCKET_EVENTS uk_socket_evd_init_from(&al->evd, &al_listener->evd); uk_socket_evd_laddr_set_from(&al->evd, &al_listener->evd); - uk_socket_evd_raddr_set(&al->evd, addr, *addr_len); + uk_socket_evd_raddr_set(&al->evd, addr, (addr_len ? *addr_len : 0)); +#endif /* CONFIG_LIBPOSIX_SOCKET_EVENTS */ if (flags & SOCK_NONBLOCK) mode |= O_NONBLOCK;