From: Timo Sirainen Date: Thu, 12 Jun 2014 21:09:23 +0000 (+0300) Subject: lib: Changed net_geterror() to return errno instead of -1 if getsockopt() fails. X-Git-Tag: 2.2.14.rc1~409 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bed2cec1eb5f445eb45b9eacc9a3aabd34edd44a;p=thirdparty%2Fdovecot%2Fcore.git 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 --- diff --git a/src/lib/net.c b/src/lib/net.c index fc641d6570..4ba71811db 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -961,8 +961,12 @@ int net_geterror(int fd) 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; }