mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(lwip): prevent integer overflow in sys_arch_sem_wait timeout
This commit is contained in:
@@ -164,8 +164,12 @@ u32_t
|
|||||||
sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
|
sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
|
||||||
{
|
{
|
||||||
BaseType_t ret;
|
BaseType_t ret;
|
||||||
|
/* * Protect against Integer Overflow:
|
||||||
if (!timeout) {
|
* If timeout is 0 (LwIP infinite wait), or if it's so large that adding
|
||||||
|
* portTICK_PERIOD_MS would overflow the 32-bit unsigned integer,
|
||||||
|
* we force it to wait infinitely.
|
||||||
|
*/
|
||||||
|
if (!timeout || timeout >= (UINT32_MAX - portTICK_PERIOD_MS)) {
|
||||||
/* wait infinite */
|
/* wait infinite */
|
||||||
ret = xSemaphoreTake((QueueHandle_t)sem, portMAX_DELAY);
|
ret = xSemaphoreTake((QueueHandle_t)sem, portMAX_DELAY);
|
||||||
LWIP_ASSERT("taking semaphore failed", ret == pdTRUE);
|
LWIP_ASSERT("taking semaphore failed", ret == pdTRUE);
|
||||||
|
|||||||
Reference in New Issue
Block a user