diff options
author | Jo-Philipp Wich <jo@mein.io> | 2025-01-25 01:24:14 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2025-01-25 01:24:14 +0100 |
commit | 5cbd32514187f0888227acef120e869cc78ff53d (patch) | |
tree | 5c6ebc646ef80ed0dc91c7fcd43841aca31ca89d /lib | |
parent | eb529ff233f80760f4dd10cb641288c4528da797 (diff) |
socket: fix AF_PACKET recvmsg() and sockaddr formatting
- Do not unconditionally pass the `MSG_CMSG_CLOEXEC` flag to `recvmsg()`
invocations as not all protocol specific recvmsg implementations in the
kernel tolerate it; `packet_recvmsg()` for example will immediately
return yield `EINVAL` if any non-whitelisted flag is passed.
- Ensure that the HW address string buffer is zero-terminated when
converting MAC addresses from C to ucode values.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/socket.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/socket.c b/lib/socket.c index db77188..c91898a 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -306,13 +306,16 @@ hwaddr_to_uv(uint8_t *addr, size_t alen) char buf[sizeof("FF:FF:FF:FF:FF:FF:FF:FF")], *p = buf; const char *hex = "0123456789ABCDEF"; - for (size_t i = 0; i < alen && i < 8; i++) { + if (alen > 8) + alen = 8; + + for (size_t i = 0; i < alen; i++) { if (i) *p++ = ':'; *p++ = hex[addr[i] / 16]; *p++ = hex[addr[i] % 16]; } - return ucv_string_new(buf); + return ucv_string_new_length(buf, alen); } static bool @@ -3920,10 +3923,6 @@ uc_socket_inst_recvmsg(uc_vm_t *vm, size_t nargs) flagval = flags ? ucv_int64_get(flags) : 0; -#if defined(__linux__) - flagval |= MSG_CMSG_CLOEXEC; -#endif - /* prepare ancillary data buffer */ if (anclength) { size_t sz = ucv_to_unsigned(anclength); |