pbuf_realloc: check that mem_trim does not move the memory

Our own implementation does not do this, but overridden implementations
calling 'realloc()' might invalidly do this
This commit is contained in:
Simon Goldschmidt 2021-05-12 21:00:10 +02:00
parent b0e347158d
commit fa5ca55c9d

View File

@ -441,8 +441,11 @@ pbuf_realloc(struct pbuf *p, u16_t new_len)
#endif /* LWIP_SUPPORT_CUSTOM_PBUF */ #endif /* LWIP_SUPPORT_CUSTOM_PBUF */
) { ) {
/* reallocate and adjust the length of the pbuf that will be split */ /* reallocate and adjust the length of the pbuf that will be split */
q = (struct pbuf *)mem_trim(q, (mem_size_t)(((u8_t *)q->payload - (u8_t *)q) + rem_len)); struct pbuf *r = (struct pbuf *)mem_trim(q, (mem_size_t)(((u8_t *)q->payload - (u8_t *)q) + rem_len));
LWIP_ASSERT("mem_trim returned q == NULL", q != NULL); LWIP_ASSERT("mem_trim returned r == NULL", r != NULL);
/* help to detect faulty overridden implementation of mem_trim */
LWIP_ASSERT("mem_trim returned r != q", r == q);
LWIP_UNUSED_ARG(r);
} }
/* adjust length fields for new last pbuf */ /* adjust length fields for new last pbuf */
q->len = rem_len; q->len = rem_len;