Module Name:    src
Committed By:   dholland
Date:           Tue Jun 10 17:18:18 UTC 2014

Modified Files:
        src/usr.sbin/ypbind: ypbind.c

Log Message:
Factor out some rpc validation code.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/usr.sbin/ypbind/ypbind.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ypbind/ypbind.c
diff -u src/usr.sbin/ypbind/ypbind.c:1.91 src/usr.sbin/ypbind/ypbind.c:1.92
--- src/usr.sbin/ypbind/ypbind.c:1.91	Tue Jun 10 17:18:02 2014
+++ src/usr.sbin/ypbind/ypbind.c	Tue Jun 10 17:18:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $	*/
+/*	$NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <[email protected]>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef LINT
-__RCSID("$NetBSD: ypbind.c,v 1.91 2014/06/10 17:18:02 dholland Exp $");
+__RCSID("$NetBSD: ypbind.c,v 1.92 2014/06/10 17:18:18 dholland Exp $");
 #endif
 
 #include <sys/types.h>
@@ -342,6 +342,28 @@ purge_bindingdir(const char *dirpath)
 // sunrpc twaddle
 
 /*
+ * Check if the info coming in is (at least somewhat) valid.
+ */
+static int
+rpc_is_valid_response(char *name, struct sockaddr_in *addr)
+{
+	if (name == NULL) {
+		return 0;
+	}
+
+	if (_yp_invalid_domain(name)) {
+		return 0;
+	}
+
+	/* don't support insecure servers by default */
+	if (!insecure && ntohs(addr->sin_port) >= IPPORT_RESERVED) {
+		return 0;
+	}
+
+	return 1;
+}
+
+/*
  * LOOPBACK IS MORE IMPORTANT: PUT IN HACK
  */
 static void
@@ -357,15 +379,9 @@ rpc_received(char *dom_name, struct sock
 	DPRINTF("returned from %s about %s\n",
 		inet_ntoa(raddrp->sin_addr), dom_name);
 
-	if (dom_name == NULL)
-		return;
-
-	if (_yp_invalid_domain(dom_name))
-		return;	
-
-		/* don't support insecure servers by default */
-	if (!insecure && ntohs(raddrp->sin_port) >= IPPORT_RESERVED)
+	if (!rpc_is_valid_response(dom_name, raddrp)) {
 		return;
+	}
 
 	for (dom = domains; dom != NULL; dom = dom->dom_next)
 		if (!strcmp(dom->dom_name, dom_name))

Reply via email to