From 31716a4960e9fc629cc534a9e2eef1b4779f94a7 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 25 Jan 2019 17:19:13 +0100 Subject: [PATCH] mdns: fixed crash on free undefined ptr after skipped strdup Shortcircuit evaluation may cause skip of _mdns_strdup_check of any further question field, which after clear_rx_packet freed undefined memory. Fixes https://ezredmine.espressif.cn:8765/issues/28465 --- components/mdns/mdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mdns/mdns.c b/components/mdns/mdns.c index 2faf57ac1..179a06da6 100644 --- a/components/mdns/mdns.c +++ b/components/mdns/mdns.c @@ -2575,7 +2575,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) parsed_packet->discovery = true; mdns_srv_item_t * a = _mdns_server->services; while (a) { - mdns_parsed_question_t * question = (mdns_parsed_question_t *)malloc(sizeof(mdns_parsed_question_t)); + mdns_parsed_question_t * question = (mdns_parsed_question_t *)calloc(1, sizeof(mdns_parsed_question_t)); if (!question) { HOOK_MALLOC_FAILED; goto clear_rx_packet; @@ -2603,7 +2603,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet) parsed_packet->probe = true; } - mdns_parsed_question_t * question = (mdns_parsed_question_t *)malloc(sizeof(mdns_parsed_question_t)); + mdns_parsed_question_t * question = (mdns_parsed_question_t *)calloc(1, sizeof(mdns_parsed_question_t)); if (!question) { HOOK_MALLOC_FAILED; goto clear_rx_packet;