From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 1/3] mount.nfs: Don't leak socket in nfs_ca_sockname()
Date: Fri, 25 Mar 2011 17:38:06 -0400 [thread overview]
Message-ID: <20110325213806.27166.56852.stgit@matisse.1015granger.net> (raw)
In-Reply-To: <20110325213559.27166.71461.stgit@matisse.1015granger.net>
Ensure the test socket is always closed before nfs_ca_sockname()
returns. Otherwise it's orphaned.
BugLink: https://bugzilla.linux-nfs.org/show_bug.cgi?id=197
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
utils/mount/network.c | 28 +++++++++++++---------------
1 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/utils/mount/network.c b/utils/mount/network.c
index 9b6504d..52a5389 100644
--- a/utils/mount/network.c
+++ b/utils/mount/network.c
@@ -1095,7 +1095,7 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
.sin6_family = AF_INET6,
.sin6_addr = IN6ADDR_ANY_INIT,
};
- int sock;
+ int sock, result = 0;
sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0)
@@ -1103,28 +1103,26 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
switch (sap->sa_family) {
case AF_INET:
- if (bind(sock, SAFE_SOCKADDR(&sin), sizeof(sin)) < 0) {
- close(sock);
- return 0;
- }
+ if (bind(sock, SAFE_SOCKADDR(&sin), sizeof(sin)) < 0)
+ goto out;
break;
case AF_INET6:
- if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0) {
- close(sock);
- return 0;
- }
+ if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0)
+ goto out;
break;
default:
errno = EAFNOSUPPORT;
- return 0;
+ goto out;
}
- if (connect(sock, sap, salen) < 0) {
- close(sock);
- return 0;
- }
+ if (connect(sock, sap, salen) < 0)
+ goto out;
- return !getsockname(sock, buf, buflen);
+ result = !getsockname(sock, buf, buflen);
+
+out:
+ close(sock);
+ return result;
}
/*
next prev parent reply other threads:[~2011-03-25 21:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-25 21:37 [PATCH 0/3] Three short subjects for nfs-utils Chuck Lever
2011-03-25 21:38 ` Chuck Lever [this message]
2011-03-25 21:38 ` [PATCH 2/3] statd: Remove vestigial "-w" option from man page synopsis Chuck Lever
2011-03-25 21:38 ` [PATCH 3/3] exports: add a configurable time-to-live for the kernel cache entries Chuck Lever
[not found] ` <20110325213559.27166.71461.stgit-RytpoXr2tKZ9HhUboXbp9zCvJB+x5qRC@public.gmane.org>
2011-04-06 15:10 ` [PATCH 0/3] Three short subjects for nfs-utils Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110325213806.27166.56852.stgit@matisse.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).