From 32e219a9fc4ef727e133bd9bda04afb245ca7b9a Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 17 Apr 2019 13:30:33 +0200 Subject: [PATCH] coap_debug.c: Fix len parameter for inet_ntop() On RIOT, inet_ntop() expects the size parameter to reflect the length of the given address. A larger value causes inet_ntop() to return ENOSPC. This change passes the address size as a workaround, or the actual number of remaining bytes in the output buffer in case less than address size bytes remain. --- src/coap_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coap_debug.c b/src/coap_debug.c index 52518ce7..403fedb7 100644 --- a/src/coap_debug.c +++ b/src/coap_debug.c @@ -196,7 +196,8 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le } /* Cast needed for Windows, since it doesn't have the correct API signature. */ - if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)p, len) == 0) { + if (inet_ntop(addr->addr.sa.sa_family, addrptr, (char *)p, + min(len, addr->size)) == 0) { perror("coap_print_addr"); return 0; }