async.[ch]: Fix flexible array member 'token' warning

Make token[] token[8] as the maximum size of a token is 8 bytes

Check that we do not overflow coap_async_state_t when copying in
the token.
This commit is contained in:
Jon Shallow committed 2018-05-22 11:32:58 +01:00
1 parent 856236dc6c
commit a17757ec6e
2 files changed
+6 -6

No files matched your search

+1 -1
View File
@@ -48,7 +48,7 @@ typedef struct coap_async_state_t {
coap_tid_t id; /**< transaction id */
struct coap_async_state_t *next; /**< internally used for linking */
size_t tokenlen; /**< length of the token */
unsigned char token[]; /**< the token to use in a response */
uint8_t token[8]; /**< the token to use in a response */
} coap_async_state_t;
/* Definitions for Async Status Flags These flags can be used to control the
+5 -5
View File
@@ -47,14 +47,13 @@ coap_register_async(coap_context_t *context, coap_session_t *session,
}
/* store information for handling the asynchronous task */
s = (coap_async_state_t *)coap_malloc(sizeof(coap_async_state_t) +
request->token_length);
s = (coap_async_state_t *)coap_malloc(sizeof(coap_async_state_t));
if (!s) {
coap_log(LOG_CRIT, "coap_register_async: insufficient memory\n");
return NULL;
}
memset(s, 0, sizeof(coap_async_state_t) + request->token_length);
memset(s, 0, sizeof(coap_async_state_t));
/* set COAP_ASYNC_CONFIRM according to request's type */
s->flags = flags & ~COAP_ASYNC_CONFIRM;
@@ -66,8 +65,9 @@ coap_register_async(coap_context_t *context, coap_session_t *session,
s->id = id;
if (request->token_length) {
s->tokenlen = request->token_length;
memcpy(s->token, request->token, request->token_length);
/* A token can be up to 8 bytes */
s->tokenlen = (request->token_length > 8) ? 8 : request->token_length;
memcpy(s->token, request->token, s->tokenlen);
}
coap_touch_async(s);