From 860651ebd89072fa6fdcdd2dceeee96e5f088c18 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 30 Oct 2018 14:31:57 +0100 Subject: socket.c: fix IP and port buffer sizes Use INET6_ADDRSTRLEN (46) instead of 64 for IP address buffers, and 6 instead of 16 for port buffers (the highest possible port number is 65535). Change-Id: Ia25e2f3277ad2f60df31c08d12f42c1e6d2a14a6 --- src/socket.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/socket.c b/src/socket.c index c7e1c9dd..0e17a28d 100644 --- a/src/socket.c +++ b/src/socket.c @@ -57,7 +57,7 @@ static struct addrinfo *addrinfo_helper(uint16_t family, uint16_t type, uint8_t const char *host, uint16_t port, bool passive) { struct addrinfo hints, *result; - char portbuf[16]; + char portbuf[6]; int rc; snprintf(portbuf, sizeof(portbuf), "%u", port); @@ -698,7 +698,7 @@ static int osmo_sock_get_name2(int fd, char *ip, size_t ip_len, char *port, size { struct sockaddr sa; socklen_t len = sizeof(sa); - char ipbuf[64], portbuf[16]; + char ipbuf[INET6_ADDRSTRLEN], portbuf[6]; int rc; rc = local ? getsockname(fd, &sa, &len) : getpeername(fd, &sa, &len); @@ -769,8 +769,8 @@ int osmo_sock_get_remote_ip_port(int fd, char *port, size_t len) */ char *osmo_sock_get_name(void *ctx, int fd) { - char hostbuf_l[64], hostbuf_r[64]; - char portbuf_l[16], portbuf_r[16]; + char hostbuf_l[INET6_ADDRSTRLEN], hostbuf_r[INET6_ADDRSTRLEN]; + char portbuf_l[6], portbuf_r[6]; /* get local */ if (osmo_sock_get_name2(fd, hostbuf_l, sizeof(hostbuf_l), portbuf_l, sizeof(portbuf_l), true)) -- cgit v1.2.3