diff --git a/src/option.c b/src/option.c index 38b3ffef..c7bd748f 100644 --- a/src/option.c +++ b/src/option.c @@ -543,6 +543,14 @@ coap_new_optlist(uint16_t number, ) { coap_optlist_t *node; +#ifdef WITH_LWIP + if (length > MEMP_LEN_COAPOPTLIST) { + coap_log(LOG_CRIT, + "coap_new_optlist: size too large (%zu > MEMP_LEN_COAPOPTLIST)\n", + length); + return NULL; + } +#endif /* WITH_LWIP */ node = coap_malloc_type(COAP_OPTLIST, sizeof(coap_optlist_t) + length); if (node) { diff --git a/src/str.c b/src/str.c index 7015d762..929233e6 100644 --- a/src/str.c +++ b/src/str.c @@ -11,8 +11,18 @@ #include coap_string_t *coap_new_string(size_t size) { - coap_string_t *s = - (coap_string_t *)coap_malloc_type(COAP_STRING, sizeof(coap_string_t) + size + 1); + coap_string_t *s; +#ifdef WITH_LWIP + if (size >= MEMP_LEN_COAPSTRING) { + coap_log(LOG_CRIT, + "coap_new_string: size too large (%zu +1 > MEMP_LEN_COAPSTRING)\n", + size); + return NULL; + } +#endif /* WITH_LWIP */ + assert(size+1 != 0); + s = (coap_string_t *)coap_malloc_type(COAP_STRING, + sizeof(coap_string_t) + size + 1); if ( !s ) { coap_log(LOG_CRIT, "coap_new_string: malloc: failed\n"); return NULL;