From 2facd2d64d579e614273f7f674290969e03ee89d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 19 Sep 2016 12:20:20 +0200 Subject: [PATCH] Apply modified patch from Daniel Elstner to fix bug #49124: mDNS should not use snprintf() --- src/apps/mdns/mdns.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/apps/mdns/mdns.c b/src/apps/mdns/mdns.c index 6fc7ce7f..7c02c914 100644 --- a/src/apps/mdns/mdns.c +++ b/src/apps/mdns/mdns.c @@ -504,9 +504,15 @@ mdns_build_reverse_v4_domain(struct mdns_domain *domain, const ip4_addr_t *addr) memset(domain, 0, sizeof(struct mdns_domain)); ptr = (const u8_t *) addr; for (i = sizeof(ip4_addr_t) - 1; i >= 0; i--) { - char buf[4]; - size_t len = snprintf(buf, sizeof(buf), "%d", ptr[i]); - res = mdns_domain_add_label(domain, buf, (u8_t)len); + char buf[3]; + size_t pos = sizeof(buf); + u8_t val = ptr[i]; + do { + pos--; + buf[pos] = '0' + (val % 10); + val /= 10; + } while (val != 0); /* loop is correct because u8_t needs at most 3 chars */ + res = mdns_domain_add_label(domain, &buf[pos], (u8_t)(3 - pos)); LWIP_ERROR("mdns_build_reverse_v4_domain: Failed to add label", (res == ERR_OK), return res); } res = mdns_domain_add_label(domain, REVERSE_PTR_V4_DOMAIN, (u8_t)(sizeof(REVERSE_PTR_V4_DOMAIN)-1));