Change in libosmocore[master]: socket.c: fix IP and port buffer sizes

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Nov 6 21:44:28 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11520 )

Change subject: socket.c: fix IP and port buffer sizes
......................................................................

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
---
M src/socket.c
1 file changed, 4 insertions(+), 4 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Neels Hofmeyr: Looks good to me, but someone else must approve
  Pau Espin Pedrol: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/socket.c b/src/socket.c
index c7e1c9d..0e17a28 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -57,7 +57,7 @@
 					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 @@
 {
 	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 @@
  */
 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))

-- 
To view, visit https://gerrit.osmocom.org/11520
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia25e2f3277ad2f60df31c08d12f42c1e6d2a14a6
Gerrit-Change-Number: 11520
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181106/c77aa88c/attachment.htm>


More information about the gerrit-log mailing list