mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
coap_debug.c: Improve len parameter handling for inet_ntop()
Commit 32e219a has resolved an issue with the size parameter for
inet_ntop() in a way that introduces errors on certain Linux
platforms. This change now passes the exact size for AF_INET
and AF_INET6 to fix that.
This commit is contained in:
1 parent
a5f434e685
commit
552fc37cde
1 file changed
+4
-1
+4
-1
@@ -174,11 +174,13 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
|
||||
const void *addrptr = NULL;
|
||||
in_port_t port;
|
||||
unsigned char *p = buf;
|
||||
size_t need_buf;
|
||||
|
||||
switch (addr->addr.sa.sa_family) {
|
||||
case AF_INET:
|
||||
addrptr = &addr->addr.sin.sin_addr;
|
||||
port = ntohs(addr->addr.sin.sin_port);
|
||||
need_buf = INET_ADDRSTRLEN;
|
||||
break;
|
||||
case AF_INET6:
|
||||
if (len < 7) /* do not proceed if buffer is even too short for [::]:0 */
|
||||
@@ -188,6 +190,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
|
||||
|
||||
addrptr = &addr->addr.sin6.sin6_addr;
|
||||
port = ntohs(addr->addr.sin6.sin6_port);
|
||||
need_buf = INET6_ADDRSTRLEN;
|
||||
|
||||
break;
|
||||
default:
|
||||
@@ -197,7 +200,7 @@ 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,
|
||||
min(len, addr->size)) == 0) {
|
||||
min(len, need_buf)) == 0) {
|
||||
perror("coap_print_addr");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user