Skip to content

Commit 4b2cbe8

Browse files
M1chacfriedt
authored andcommitted
net: mqtt_sn: fix returning address from zsock_recvfrom
The fix in 1264a92 was incomplete, because it doesn't initialize the variable. To quote from opengroup [1]: address_len Either a null pointer, if address is a null pointer, or a pointer to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address. This caused the returned address to be incomplete, because it got truncated depending on what addrlen_local got initialized with implicitly. This broke talking to discovered MQTT-SN gateways. I intend to implement integration tests for the MQTT-SN UDP transport to prevent such issues in future, but that will be done in a separate PR. [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html Signed-off-by: Michael Zimmermann <[email protected]>
1 parent f3017a4 commit 4b2cbe8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static ssize_t tp_udp_recvfrom(struct mqtt_sn_client *client, void *buffer, size
213213
struct mqtt_sn_transport_udp *udp = UDP_TRANSPORT(client->transport);
214214
int rc;
215215
struct sockaddr *srcaddr = src_addr;
216-
socklen_t addrlen_local;
216+
socklen_t addrlen_local = *addrlen;
217217

218218
rc = zsock_recvfrom(udp->sock, buffer, length, 0, src_addr, &addrlen_local);
219219
LOG_DBG("recv %d", rc);

0 commit comments

Comments
 (0)