[riot-notifications] [RIOT-OS/RIOT] sock/async: add function to retrieve session object of current DTLS event (#15755)

Aiman Ismail notifications at github.com
Thu Jan 14 01:22:56 CET 2021


@pokgak commented on this pull request.



> @@ -87,6 +87,7 @@ static int _read(struct dtls_context_t *ctx, session_t *session, uint8_t *buf,
     sock->buffer.session = session;
 #ifdef SOCK_HAS_ASYNC
     if (sock->async_cb != NULL) {
+        memcpy(&sock->async_cb_session, session, sizeof(session_t));

Okay apparently I misunderstood how `sock_async` works. Although it seems that `sock->async_cb` is called inside of `_event`/`_read`, it is actually executed after leaving those functions. I discovered this after adding some printf. Can you confirm this @miri64?

This means, we accessed the session after we set it to `NULL`, causing it to segfault. So I tested without setting `async_cb_session` to `NULL` and it worked! Though I'm not sure if this have any other side effects..

Here is the log of the working test with more printf added:
```
main(): This is RIOT! (Version: 2021.01-devel-1872-gfdb01-pr/dtls/get_event_session_pointer)                                                                                                                       
DTLS sock example application                                                                                                                                                                                      
All up, running the shell now                                                                                                                                                                                      
> dtlss start                                                                                                                                                                                                      
dtlss start                                                                                                                                                                                                        
> entering _event                                                                                                                                                                                                  
leaving _event                                                                                                                                                                                                     
entering _dtls_handler                                                                                                                                                                                             
event: SOCK_ASYNC_CONN_RECV
Session handshake received: Peer: FE:80:00:00:00:00:00:00:E8:BC:C0:FF:FE:06:47:8B: Port: 12345 Family: 4
New client connected
leaving _dtls_handler
entering _dtls_handler
event: SOCK_ASYNC_CONN_RDY
Session became ready: Peer: FE:80:00:00:00:00:00:00:E8:BC:C0:FF:FE:06:47:8B: Port: 12345 Family: 4
leaving _dtls_handler
entering _read
leaving _read
entering _dtls_handler
event: SOCK_ASYNC_MSG_RECV
Message received: done mesg recevd
Peer: FE:80:00:00:00:00:00:00:E8:BC:C0:FF:FE:06:47:8B: Port: 12345 Family: 4
Received 12 bytes -- (echo)
leaving _dtls_handler
entering _dtls_handler
leaving _dtls_handler
entering _event
leaving _event
entering _dtls_handler
event: SOCK_ASYNC_CONN_FIN
Session was destroyed by peer: Peer: FE:80:00:00:00:00:00:00:E8:BC:C0:FF:FE:06:47:8B: Port: 12345 Family: 4

leaving _dtls_handler

```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/15755#discussion_r556963651
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210113/e0e739c1/attachment-0001.htm>


More information about the notifications mailing list