File 0003-autofs-5.1.4-fix-fd-leak-in-rpc_do_create_client.patch of Package autofs.23455

From 3fd936200694c7b323b1721bf2b08f1d48c868c8 Mon Sep 17 00:00:00 2001
From: Ian Kent <raven@themaw.net>
Date: Fri, 11 May 2018 16:38:37 +0800
Subject: [PATCH] autofs-5.1.4 - fix fd leak in rpc_do_create_client()

Commit 94f87e203a (fix create_client() RPC client handling) fixed
possible use of an invalid RPC client handle but the change neglected
to account of a check in rpc_do_create_client() that would open a new
file descriptor without checking if the passed if descriptor was
already opened.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG      |    1 +
 lib/rpc_subs.c |    4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -180,6 +180,7 @@
 - link daemon with pthread library (Debian patch).
 - manpage corrections (Debian patch).
 - fix manpages hyphenation (Debian patch).
+- fix fd leak in rpc_do_create_client().
 
 04/06/2014 autofs-5.1.0
 =======================
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -182,7 +182,7 @@ static int rpc_do_create_client(struct s
 	in4_laddr.sin_addr.s_addr = htonl(INADDR_ANY);
 	slen = sizeof(struct sockaddr_in);
 
-	if (!info->client) {
+	if (!info->client && *fd == RPC_ANYSOCK) {
 		struct sockaddr *laddr;
 
 		*fd = open_sock(addr->sa_family, type, proto);
@@ -295,7 +295,7 @@ static int rpc_do_create_client(struct s
 	 * it would bind to a reserved port, which has been shown to
 	 * exhaust the reserved port range in some situations.
 	 */
-	if (!info->client) {
+	if (!info->client && *fd == RPC_ANYSOCK) {
 		*fd = open_sock(addr->sa_family, type, proto);
 		if (*fd < 0) {
 			ret = -errno;
openSUSE Build Service is sponsored by