Change in libosmocore[master]: osmo_sock_get_name_*: Ensure string is returned in error case

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri May 10 07:30:52 UTC 2019


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/13960


Change subject: osmo_sock_get_name_*: Ensure string is returned in error case
......................................................................

osmo_sock_get_name_*: Ensure string is returned in error case

osmo_sock_get_name_buf():
In case the getsockname() call is failing for some weird reason,
we shouldn't return an uninitialized, non-zero-terminated string
buffer to the caller, as most callers will be too lazy to test the
return value.

This holds even more true for users of the internal
osmo_sock_get_name2() and osmo_sock_get_name2_c() functions which indeed
very much ignore the return value of osmo_sock_get_name_buf().

Change-Id: I2d56327e96b7a6783cca38b828c5ee74aed776ae
---
M src/socket.c
1 file changed, 6 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/60/13960/1

diff --git a/src/socket.c b/src/socket.c
index 7c412b6..78c0a58 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -805,12 +805,16 @@
 	int rc;
 
 	/* get local */
-	if ((rc = osmo_sock_get_ip_and_port(fd, hostbuf_l, sizeof(hostbuf_l), portbuf_l, sizeof(portbuf_l), true)))
+	if ((rc = osmo_sock_get_ip_and_port(fd, hostbuf_l, sizeof(hostbuf_l), portbuf_l, sizeof(portbuf_l), true))) {
+		osmo_strlcpy(str, "<error-in-getsockname>", str_len);
 		return rc;
+	}
 
 	/* get remote */
-	if (osmo_sock_get_ip_and_port(fd, hostbuf_r, sizeof(hostbuf_r), portbuf_r, sizeof(portbuf_r), false) != 0)
+	if (osmo_sock_get_ip_and_port(fd, hostbuf_r, sizeof(hostbuf_r), portbuf_r, sizeof(portbuf_r), false) != 0) {
+		osmo_strlcpy(str, "<error-in-getsockname>", str_len);
 		return snprintf(str, str_len, "r=NULL<->l=%s:%s", hostbuf_l, portbuf_l);
+	}
 
 	return snprintf(str, str_len, "r=%s:%s<->l=%s:%s", hostbuf_r, portbuf_r, hostbuf_l, portbuf_l);
 }

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2d56327e96b7a6783cca38b828c5ee74aed776ae
Gerrit-Change-Number: 13960
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190510/591ccf3d/attachment.html>


More information about the gerrit-log mailing list