summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2018-10-30 14:31:57 +0100
committerHarald Welte <laforge@gnumonks.org>2018-11-06 21:44:28 +0000
commit860651ebd89072fa6fdcdd2dceeee96e5f088c18 (patch)
tree670ce04740e30b00047cfaae1e01979d214014ec
parentba2bd2eeb18ed361a0ee6038c8a3f114748aa576 (diff)
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
-rw-r--r--src/socket.c8
1 files 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))