From 75a8e8640a0bacc88b40cfb893fc947b56651473 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 10 Jan 2025 11:22:46 +0100 Subject: [PATCH] fix(mdns): Fixed potential overflow when allocating txt data Closes coverity warning: 470092 Overflowed integer argument --- components/mdns/mdns.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 6a7df9d33..2cda7b229 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -3486,8 +3486,9 @@ static void _mdns_result_txt_create(const uint8_t *data, size_t len, mdns_txt_it uint16_t i = 0, y; size_t partLen = 0; int num_items = _mdns_txt_items_count_get(data, len); - if (num_items < 0) { - return;//error + if (num_items < 0 || num_items > SIZE_MAX / sizeof(mdns_txt_item_t)) { + // Error: num_items is incorrect (or too large to allocate) + return; } if (!num_items) {