dovecot-2.2: lib: Changed net_geterror() to return errno instead...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 12 23:20:36 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/2e239d925c09
changeset: 17461:2e239d925c09
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 13 00:09:23 2014 +0300
description:
lib: Changed net_geterror() to return errno instead of -1 if getsockopt() fails.
None of the callers were actually checking for the -1 error value but
instead just passing it to strerror(). Since this error should just about
never happen it's better to just return a usable return value than try to
remember to handle errors that can't normally even happen.
Found by Coverity

diffstat:

 src/lib/net.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (18 lines):

diff -r c699a3eb0b75 -r 2e239d925c09 src/lib/net.c
--- a/src/lib/net.c	Fri Jun 13 00:05:16 2014 +0300
+++ b/src/lib/net.c	Fri Jun 13 00:09:23 2014 +0300
@@ -961,8 +961,12 @@
 	int data;
 	socklen_t len = sizeof(data);
 
-	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1)
-		return -1;
+	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1) {
+		/* we're now really returning the getsockopt()'s error code
+		   instead of the socket's, but normally we should never get
+		   here anyway. */
+		return errno;
+	}
 
 	return data;
 }


More information about the dovecot-cvs mailing list