mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-23 23:51:03 +03:00
resource.c: Fix run-time exceptions and use C89 syntax.
Fix read-after-free of the token by moving the code before the free. Fix print of uninitialized heap memory if the token length is 0. Use C89 syntax for compatibility.
This commit is contained in:
1 parent
40144769f4
commit
5935867e68
1 file changed
+8
-10
+8
-10
@@ -706,6 +706,14 @@ coap_delete_observer(coap_resource_t *resource, coap_session_t *session,
|
||||
|
||||
s = coap_find_observer(resource, session, token);
|
||||
|
||||
if ( s && coap_get_log_level() >= LOG_DEBUG ) {
|
||||
char outbuf[2 * 8 + 1] = "";
|
||||
unsigned int i;
|
||||
for ( i = 0; i < s->token_length; i++ )
|
||||
snprintf( &outbuf[2 * i], 3, "%02x", s->token[i] );
|
||||
coap_log( LOG_DEBUG, "removed observer tid %s\n", outbuf );
|
||||
}
|
||||
|
||||
if (resource->subscribers && s) {
|
||||
LL_DELETE(resource->subscribers, s);
|
||||
coap_session_release( session );
|
||||
@@ -714,16 +722,6 @@ coap_delete_observer(coap_resource_t *resource, coap_session_t *session,
|
||||
COAP_FREE_TYPE(subscription,s);
|
||||
}
|
||||
|
||||
if (s) {
|
||||
char outbuf[2*s->token_length+1];
|
||||
unsigned int i;
|
||||
for (i = 0; i < s->token_length; i++) {
|
||||
snprintf(&outbuf[2*i], 3,
|
||||
"%02x", s->token[i]);
|
||||
}
|
||||
coap_log(LOG_DEBUG, "removed observer tid %s\n", outbuf);
|
||||
}
|
||||
|
||||
return s != NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user