Skip to contentSkip to conversation

mount.nfs: getport() should avoid modifying passed-in arguments

PATCH In review Chuck Lever 1 participant 1 message Aug 21, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/4 mount.nfs: getport() should avoid modifying passed-in arguments

Defensive coding: getport() shouldn't alter the passed-in server address, but should treat it as read only. Have it operate on a copy.

---

 utils/mount/network.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
utils/mount/network.c +9 -5
index eb59c1f..9f803a4 100644
@@ -303,14 +303,16 @@ static unsigned short getport(struct sockaddr_in *saddr,
 				unsigned long version,
 				unsigned int proto)
 {
+	struct sockaddr_in bind_saddr;
 	unsigned short port = 0;
 	int socket;
 	CLIENT *clnt = NULL;
 	enum clnt_stat stat;
+ 
+	bind_saddr = *saddr;
+	bind_saddr.sin_port = htons(PMAPPORT);
 
-	saddr->sin_port = htons(PMAPPORT);
-
-	socket = get_socket(saddr, proto, PMAP_TIMEOUT, FALSE, FALSE);
+	socket = get_socket(&bind_saddr, proto, PMAP_TIMEOUT, FALSE, FALSE);
 	if (socket == RPC_ANYSOCK) {
 		if (proto == IPPROTO_TCP &&
 		    rpc_createerr.cf_error.re_errno == ETIMEDOUT)
@@ -320,14 +322,16 @@ static unsigned short getport(struct sockaddr_in *saddr,
 
 	switch (proto) {
 	case IPPROTO_UDP:
-		clnt = clntudp_bufcreate(saddr,
+		clnt = clntudp_bufcreate(&bind_saddr,
 					 PMAPPROG, PMAPVERS,
 					 RETRY_TIMEOUT, &socket,
 					 RPCSMALLMSGSIZE,
 					 RPCSMALLMSGSIZE);
 		break;
 	case IPPROTO_TCP:
-		clnt = clnttcp_create(saddr, PMAPPROG, PMAPVERS, &socket,
+		clnt = clnttcp_create(&bind_saddr,
+				      PMAPPROG, PMAPVERS,
+				      &socket,
 				      RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
 		break;
 	}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs