[PATCH] libosmocore[master]: socket: use inet_ntop() instead of inet_ntoa() in osmo_sock_...

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

dexter gerrit-no-reply at lists.osmocom.org
Mon Jan 22 16:04:40 UTC 2018


Review at  https://gerrit.osmocom.org/5988

socket: use inet_ntop() instead of inet_ntoa() in osmo_sock_local_ip()

The function inet_ntoa() stores its result in a static buffer and
returns the pointer. When inet_ntoa() is called subsequently it
overwrite the content of its static buffer with the new result.

Since we osmo_sock_local_ip() is a library function we should use
the more safe variant inet_ntop() in order to prevent unintentionally
overwriting data that the caller might still need. Such an error
would be hard to find.

- Use the more safe inet_ntop() inestead of inet_ntoa()

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


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/88/5988/1

diff --git a/src/socket.c b/src/socket.c
index 35cce64..0378970 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -831,9 +831,9 @@
 	if (rc < 0)
 		return -EINVAL;
 	if (local_addr.sin_family == AF_INET)
-		strncpy(local_ip, inet_ntoa(local_addr.sin_addr), INET_ADDRSTRLEN);
+		inet_ntop(AF_INET, &local_addr.sin_addr, local_ip, INET_ADDRSTRLEN);
 	else if (local_addr.sin_family == AF_INET6)
-		strncpy(local_ip, inet_ntoa(local_addr.sin_addr), INET6_ADDRSTRLEN);
+		inet_ntop(AF_INET6, &local_addr.sin_addr, local_ip, INET6_ADDRSTRLEN);
 	else
 		return -EINVAL;
 

-- 
To view, visit https://gerrit.osmocom.org/5988
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9852b57736432032542bd96b6fdd4a2f08fc1f64
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list