00db10
commit 8b59c73386ddb64331ee03c29925a18dae547733
00db10
Author: Carlos O'Donell <carlos@systemhalted.org>
00db10
Date:   Wed Jul 8 02:42:11 2015 -0400
00db10
00db10
    Fix ruserok scalability with large ~/.rhosts file.
00db10
    
00db10
    Fixes bug 18557.
00db10
00db10
diff --git glibc-2.17-c758a686/inet/rcmd.c glibc-2.17-c758a686/inet/rcmd.c
00db10
index 98b3735..91623b0 100644
00db10
--- glibc-2.17-c758a686/inet/rcmd.c
00db10
+++ glibc-2.17-c758a686/inet/rcmd.c
00db10
@@ -809,29 +809,38 @@ __validuser2_sa(hostf, ra, ralen, luser, ruser, rhost)
00db10
 	*p = '\0';              /* <nul> terminate username (+host?) */
00db10
 
00db10
 	/* buf -> host(?) ; user -> username(?) */
00db10
+	if (*buf == '\0')
00db10
+	  break;
00db10
+	if (*user == '\0')
00db10
+	  user = luser;
00db10
+
00db10
+	/* First check the user part.  This is an optimization, since
00db10
+	   one should always check the host first in order to detect
00db10
+	   negative host checks (which we check for later).  */
00db10
+	ucheck = __icheckuser (user, ruser);
00db10
+
00db10
+	/* Either we found the user, or we didn't and this is a
00db10
+	   negative host check.  We must do the negative host lookup
00db10
+	   in order to preserve the semantics of stopping on this line
00db10
+	   before processing others.  */
00db10
+	if (ucheck != 0 || *buf == '-') {
00db10
+
00db10
+	    /* Next check host part */
00db10
+	    hcheck = __checkhost_sa (ra, ralen, buf, rhost);
00db10
+
00db10
+	    /* Negative '-host user(?)' match?  */
00db10
+	    if (hcheck < 0)
00db10
+		break;
00db10
 
00db10
-	/* First check host part */
00db10
-	hcheck = __checkhost_sa (ra, ralen, buf, rhost);
00db10
-
00db10
-	if (hcheck < 0)
00db10
-	    break;
00db10
-
00db10
-	if (hcheck) {
00db10
-	    /* Then check user part */
00db10
-	    if (! (*user))
00db10
-		user = luser;
00db10
-
00db10
-	    ucheck = __icheckuser (user, ruser);
00db10
-
00db10
-	    /* Positive 'host user' match? */
00db10
-	    if (ucheck > 0) {
00db10
+	    /* Positive 'host user' match?  */
00db10
+	    if (hcheck > 0 && ucheck > 0) {
00db10
 		retval = 0;
00db10
 		break;
00db10
 	    }
00db10
 
00db10
-	    /* Negative 'host -user' match? */
00db10
-	    if (ucheck < 0)
00db10
-		break;
00db10
+	    /* Negative 'host -user' match?  */
00db10
+	    if (hcheck > 0 && ucheck < 0)
00db10
+	      break;
00db10
 
00db10
 	    /* Neither, go on looking for match */
00db10
 	}