Skip to content

Commit e125164

Browse files
author
Tero Heinonen
authored
Check secure session pointer in timer callback (#61)
When timer callback is called, void pointer is given as a parameter, and it is then typecasted to secure session pointer. Added check is that session still valid before using it.
1 parent f49e596 commit e125164

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

source/coap_connection_handler.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ static secure_session_t *secure_session_find_by_timer_id(int8_t timer_id)
9797
return this;
9898
}
9999

100+
static bool is_secure_session_valid(secure_session_t *session)
101+
{
102+
secure_session_t *this = NULL;
103+
ns_list_foreach(secure_session_t, cur_ptr, &secure_session_list) {
104+
if (cur_ptr == session) {
105+
return true;
106+
}
107+
}
108+
return false;
109+
}
110+
100111
static void secure_session_delete(secure_session_t *this)
101112
{
102113
if (this) {
@@ -402,7 +413,8 @@ static int secure_session_recvfrom(int8_t socket_id, unsigned char *buf, size_t
402413
static void timer_cb(void *param)
403414
{
404415
secure_session_t *sec = param;
405-
if( sec ){
416+
417+
if( sec && is_secure_session_valid(sec)){
406418
if(sec->timer.fin_ms > sec->timer.int_ms){
407419
/* Intermediate expiry */
408420
sec->timer.fin_ms -= sec->timer.int_ms;

0 commit comments

Comments
 (0)