]> granicus.if.org Git - esp-idf/commitdiff
mdns: fixed crash on free undefined ptr after skipped strdup
authorDavid Cermak <cermak@espressif.com>
Fri, 25 Jan 2019 16:19:13 +0000 (17:19 +0100)
committerDavid Cermak <cermak@espressif.com>
Tue, 29 Jan 2019 09:10:38 +0000 (10:10 +0100)
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

index 742c47aeee70682d84840daf669352ab23e20f0f..c77c9443fa4b1924fa352f0ea5215fd86c626efd 100644 (file)
@@ -2590,7 +2590,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;
@@ -2618,7 +2618,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;