Merge pull request #747 from mrdeep1/session_release

net.c: Protect against session release in coap_io_do_io()
This commit is contained in:
obgm authored and GitHub committed 2021-09-30 16:28:52 +02:00
commit 1091e59ff4
1 file changed
+8 -17
+8 -17
View File
@@ -1753,40 +1753,31 @@ coap_io_do_io(coap_context_t *ctx, coap_tick_t now) {
if ((ep->sock.flags & COAP_SOCKET_CAN_ACCEPT) != 0)
coap_accept_endpoint(ctx, ep, now);
SESSIONS_ITER_SAFE(ep->sessions, s, rtmp) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
if ((s->sock.flags & COAP_SOCKET_CAN_READ) != 0) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
coap_read_session(ctx, s, now);
coap_session_release(s);
}
if ((s->sock.flags & COAP_SOCKET_CAN_WRITE) != 0) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
coap_write_session(ctx, s, now);
coap_session_release(s);
}
coap_session_release(s);
}
}
SESSIONS_ITER_SAFE(ctx->sessions, s, rtmp) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
if ((s->sock.flags & COAP_SOCKET_CAN_CONNECT) != 0) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
coap_connect_session(ctx, s, now);
coap_session_release( s );
}
if ((s->sock.flags & COAP_SOCKET_CAN_READ) != 0) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
if ((s->sock.flags & COAP_SOCKET_CAN_READ) != 0 && s->ref > 1) {
coap_read_session(ctx, s, now);
coap_session_release(s);
}
if ((s->sock.flags & COAP_SOCKET_CAN_WRITE) != 0) {
/* Make sure the session object is not deleted in one of the callbacks */
coap_session_reference(s);
if ((s->sock.flags & COAP_SOCKET_CAN_WRITE) != 0 && s->ref > 1) {
coap_write_session(ctx, s, now);
coap_session_release( s );
}
coap_session_release( s );
}
#endif /* ! COAP_EPOLL_SUPPORT */
}