Change in libosmocore[master]: osmo_sock_inti2_multiaddr: Fix memleak and free uninitialized mem

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/.

pespin gerrit-no-reply at lists.osmocom.org
Tue Aug 25 09:25:20 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19809 )


Change subject: osmo_sock_inti2_multiaddr: Fix memleak and free uninitialized mem
......................................................................

osmo_sock_inti2_multiaddr: Fix memleak and free uninitialized mem

Under some specific cases, res_loc could be leaked. Under some others,
res_loc and res_rem were freed without being initialized previously.

Fixes: CID#212863
Fixes: CID#212861
Change-Id: Id9c4eda6fd1172e7324aa23c81e8658967a8dd0b
---
M src/socket.c
1 file changed, 13 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/09/19809/1

diff --git a/src/socket.c b/src/socket.c
index 50d59e5..0b84b99 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -566,8 +566,10 @@
 	if (flags & OSMO_SOCK_F_CONNECT) {
 		rc = addrinfo_helper_multi(res_rem, family, type, proto, remote_hosts,
 					   remote_hosts_cnt, remote_port, false);
-		if (rc < 0)
-			return -EINVAL;
+		if (rc < 0) {
+			rc = -EINVAL;
+			goto ret_freeaddrinfo_loc;
+		}
 		/* Figure out if there's any IPv4 or IPv6  addr in the set */
 		if (family == AF_UNSPEC)
 			addrinfo_has_v4v6addr((const struct addrinfo **)res_rem, remote_hosts_cnt,
@@ -660,10 +662,15 @@
 	if (sfd >= 0)
 		close(sfd);
 ret_freeaddrinfo:
-	for (i = 0; i < local_hosts_cnt; i++)
-		freeaddrinfo(res_loc[i]);
-	for (i = 0; i < remote_hosts_cnt; i++)
-		freeaddrinfo(res_rem[i]);
+	if (flags & OSMO_SOCK_F_CONNECT) {
+		for (i = 0; i < remote_hosts_cnt; i++)
+			freeaddrinfo(res_rem[i]);
+	}
+ret_freeaddrinfo_loc:
+	if (flags & OSMO_SOCK_F_BIND) {
+		for (i = 0; i < local_hosts_cnt; i++)
+			freeaddrinfo(res_loc[i]);
+	}
 	return rc;
 }
 #endif /* HAVE_LIBSCTP */

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id9c4eda6fd1172e7324aa23c81e8658967a8dd0b
Gerrit-Change-Number: 19809
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200825/299486bf/attachment.htm>


More information about the gerrit-log mailing list