Fix handling of Token Length greater than 8

This commit is contained in:
Anmol Sarma 2015-09-05 20:46:29 +05:30
parent dd640cd229
commit c084c46b9b

View file

@ -451,10 +451,8 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
>> COAP_HEADER_VERSION_POSITION;
coap_pkt->type = (COAP_HEADER_TYPE_MASK & coap_pkt->buffer[0])
>> COAP_HEADER_TYPE_POSITION;
coap_pkt->token_len =
MIN(COAP_TOKEN_LEN,
(COAP_HEADER_TOKEN_LEN_MASK & coap_pkt->
buffer[0]) >> COAP_HEADER_TOKEN_LEN_POSITION);
coap_pkt->token_len = (COAP_HEADER_TOKEN_LEN_MASK & coap_pkt->buffer[0])
>> COAP_HEADER_TOKEN_LEN_POSITION;
coap_pkt->code = coap_pkt->buffer[1];
coap_pkt->mid = coap_pkt->buffer[2] << 8 | coap_pkt->buffer[3];
@ -463,6 +461,11 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
return BAD_REQUEST_4_00;
}
if(coap_pkt->token_len > COAP_TOKEN_LEN) {
coap_error_message = "Token Length must not be more than 8";
return BAD_REQUEST_4_00;
}
uint8_t *current_option = data + COAP_HEADER_LEN;
memcpy(coap_pkt->token, current_option, coap_pkt->token_len);