sys/net/nanocoap: return ENOENT if parsing option failed

This fixes a potential use of uninitialized len in subsequent function calls.

This was reported by scan-build
This commit is contained in:
Alexandre Abadie 2019-10-27 11:20:41 +01:00
parent 5b4b12ed07
commit 1aa1e2c8cc
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 5 additions and 0 deletions

View File

@ -586,6 +586,7 @@ ssize_t coap_opt_get_next(const coap_pkt_t *pkt, coap_optpos_t *opt,
*
* @return length of option; 0 if the option exists but is empty
* @return -ENOENT if option not found
* @return -EINVAL if option cannot be parsed
*/
ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value);
/**@}*/

View File

@ -217,6 +217,10 @@ ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value)
int len;
*value = _parse_option(pkt, start, &delta, &len);
if (!*value) {
return -EINVAL;
}
return len;
}