Skip to content

Commit

Permalink
socket: fix AF_PACKET recvmsg() and sockaddr formatting
Browse files Browse the repository at this point in the history
 - 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 <[email protected]>
  • Loading branch information
jow- committed Jan 25, 2025
1 parent eb529ff commit 5cbd325
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5cbd325

Please sign in to comment.