Change in libosmocore[master]: socket: check return code of setsockopt

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
Thu Aug 2 10:23:24 UTC 2018


dexter has submitted this change and it was merged. ( https://gerrit.osmocom.org/10288 )

Change subject: socket: check return code of setsockopt
......................................................................

socket: check return code of setsockopt

the return code of the last setsockopt() call in osmo_sock_init() is not
checked. Since all other calls to setsockopt are checked, lets check
this one as well.

- check return code of setsockopt() and close the socket on failure

Change-Id: I96dbccc3bcff35bf39979dbe0c44aadc8ce20c83
---
M src/socket.c
1 file changed, 8 insertions(+), 1 deletion(-)

Approvals:
  dexter: Verified
  Harald Welte: Looks good to me, approved



diff --git a/src/socket.c b/src/socket.c
index dc5590c..0a4e34c 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -373,7 +373,14 @@
 		return -ENODEV;
 	}
 
-	setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+	rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+	if (rc < 0) {
+		LOGP(DLGLOBAL, LOGL_ERROR,
+		     "cannot setsockopt socket: %s:%u: %s\n", host, port,
+		     strerror(errno));
+		close(sfd);
+		sfd = -1;
+	}
 
 	rc = osmo_sock_init_tail(sfd, type, flags);
 	if (rc < 0) {

-- 
To view, visit https://gerrit.osmocom.org/10288
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: I96dbccc3bcff35bf39979dbe0c44aadc8ce20c83
Gerrit-Change-Number: 10288
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180802/b59c44b4/attachment.htm>


More information about the gerrit-log mailing list