Skip to content

Commit

Permalink
net: sockets: Update msg_controllen in recvmsg properly
Browse files Browse the repository at this point in the history
If adding any control data like timestamping or pkt_info fails, the
msg_controllen wasn't properly cleared.
This commit aims to fix this by clearing the msg_controllen only when
adding control data is successful.

Fixes zephyrproject-rtos#77303

Signed-off-by: Axel Le Bourhis <axel.lebourhis@nxp.com>
  • Loading branch information
axelnxp authored and decsny committed Aug 21, 2024
1 parent 34206f5 commit 01b8f8b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions subsys/net/lib/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,17 +1575,19 @@ static inline ssize_t zsock_recv_dgram(struct net_context *ctx,
bool clear_controllen = true;

if (IS_ENABLED(CONFIG_NET_CONTEXT_TIMESTAMPING)) {
clear_controllen = false;
if (add_timestamping(ctx, pkt, msg) < 0) {
msg->msg_flags |= ZSOCK_MSG_CTRUNC;
} else {
clear_controllen = false;
}
}

if (IS_ENABLED(CONFIG_NET_CONTEXT_RECV_PKTINFO) &&
net_context_is_recv_pktinfo_set(ctx)) {
clear_controllen = false;
if (add_pktinfo(ctx, pkt, msg) < 0) {
msg->msg_flags |= ZSOCK_MSG_CTRUNC;
} else {
clear_controllen = false;
}
}

Expand Down

0 comments on commit 01b8f8b

Please sign in to comment.