Skip to content

Commit 833fde3

Browse files
Peter Tönzmlasch
authored andcommitted
[sg fromtree] net: lwm2m: Fix seg-faults if a socket was closed in the meantime
Our application (posix-naive/debug) ran into segmentaion faults, because the socket was closed between the "wait for sockets" and the second if in the first loop. Added the check also to line 690 and 720. The other uses of sock_ctx[i] are already checked against NULL Signed-off-by: Peter Tönz <[email protected]> (cherry picked from commit 46a5912)
1 parent 5571d9d commit 833fde3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,15 @@ static void socket_loop(void)
711711
}
712712

713713
for (i = 0; i < sock_nfds; ++i) {
714-
if (sys_slist_is_empty(&sock_ctx[i]->pending_sends)) {
714+
if (sock_ctx[i] != NULL &&
715+
sys_slist_is_empty(&sock_ctx[i]->pending_sends)) {
715716
next_retransmit = retransmit_request(sock_ctx[i], timestamp);
716717
if (next_retransmit < timeout) {
717718
timeout = next_retransmit;
718719
}
719720
}
720-
if (sys_slist_is_empty(&sock_ctx[i]->pending_sends) &&
721+
if (sock_ctx[i] != NULL &&
722+
sys_slist_is_empty(&sock_ctx[i]->pending_sends) &&
721723
lwm2m_rd_client_is_registred(sock_ctx[i])) {
722724
check_notifications(sock_ctx[i], timestamp);
723725
}
@@ -739,7 +741,7 @@ static void socket_loop(void)
739741

740742
for (i = 0; i < sock_nfds; i++) {
741743

742-
if (sock_ctx[i]->sock_fd < 0) {
744+
if (sock_ctx[i] != NULL && sock_ctx[i]->sock_fd < 0) {
743745
continue;
744746
}
745747

0 commit comments

Comments
 (0)