Apply modified patch from Daniel Elstner to fix bug #49124: mDNS should not use snprintf()

This commit is contained in:
Dirk Ziegelmeier 2016-09-19 12:20:20 +02:00
parent ee4cd45c98
commit 2facd2d64d

View File

@ -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));