From 8642dc4aa758538b96fa13f27d4fbd98863a0f7a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 23 Mar 2022 17:17:48 -0700 Subject: [PATCH] Fix MDNS crash on S2 Fixes #6186 --- ports/espressif/common-hal/mdns/Server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/espressif/common-hal/mdns/Server.c b/ports/espressif/common-hal/mdns/Server.c index 2f260bbde0..9da67a9145 100644 --- a/ports/espressif/common-hal/mdns/Server.c +++ b/ports/espressif/common-hal/mdns/Server.c @@ -117,6 +117,11 @@ mp_obj_t common_hal_mdns_server_find(mdns_server_obj_t *self, const char *servic next = next->next; } mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_results, NULL)); + // The empty tuple object is shared and stored in flash so return early if + // we got it. Without this we'll crash when trying to set len below. + if (num_results == 0) { + return MP_OBJ_FROM_PTR(tuple); + } next = results; // Don't error if we're out of memory. Instead, truncate the tuple. uint8_t added = 0;