00db10
commit 50fd745b4dec07e8e213cf2703b5cabcfa128225
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Mon Jun 10 14:39:09 2013 +0200
00db10
00db10
    Fix handling of netgroup cache in nscd
00db10
00db10
diff --git glibc-2.17-c758a686/nscd/connections.c glibc-2.17-c758a686/nscd/connections.c
00db10
index 7099215..69e3e7d 100644
00db10
--- glibc-2.17-c758a686/nscd/connections.c
00db10
+++ glibc-2.17-c758a686/nscd/connections.c
00db10
@@ -1779,7 +1779,7 @@ nscd_run_worker (void *p)
00db10
       else
00db10
 	{
00db10
 	  /* Get the key.  */
00db10
-	  char keybuf[MAXKEYLEN];
00db10
+	  char keybuf[MAXKEYLEN + 1];
00db10
 
00db10
 	  if (__builtin_expect (TEMP_FAILURE_RETRY (read (fd, keybuf,
00db10
 							  req.key_len))
00db10
@@ -1791,6 +1791,7 @@ nscd_run_worker (void *p)
00db10
 			 strerror_r (errno, buf, sizeof (buf)));
00db10
 	      goto close_and_out;
00db10
 	    }
00db10
+	  keybuf[req.key_len] = '\0';
00db10
 
00db10
 	  if (__builtin_expect (debug_level, 0) > 0)
00db10
 	    {
00db10
diff --git glibc-2.17-c758a686/nscd/netgroupcache.c glibc-2.17-c758a686/nscd/netgroupcache.c
00db10
index 2d6c5aa..dd06ce4 100644
00db10
--- glibc-2.17-c758a686/nscd/netgroupcache.c
00db10
+++ glibc-2.17-c758a686/nscd/netgroupcache.c
00db10
@@ -192,18 +192,26 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
00db10
 			    const char *nuser = data.val.triple.user;
00db10
 			    const char *ndomain = data.val.triple.domain;
00db10
 
00db10
-			    if (data.val.triple.host > data.val.triple.user
00db10
-				|| data.val.triple.user > data.val.triple.domain)
00db10
+			    if (nhost == NULL || nuser == NULL || ndomain == NULL
00db10
+				|| nhost > nuser || nuser > ndomain)
00db10
 			      {
00db10
-				const char *last = MAX (nhost,
00db10
-							MAX (nuser, ndomain));
00db10
-				size_t bufused = (last + strlen (last) + 1
00db10
-						  - buffer);
00db10
+				const char *last = nhost;
00db10
+				if (last == NULL
00db10
+				    || (nuser != NULL && nuser > last))
00db10
+				  last = nuser;
00db10
+				if (last == NULL
00db10
+				    || (ndomain != NULL && ndomain > last))
00db10
+				  last = ndomain;
00db10
+
00db10
+				size_t bufused
00db10
+				  = (last == NULL
00db10
+				     ? buffilled
00db10
+				     : last + strlen (last) + 1 - buffer);
00db10
 
00db10
 				/* We have to make temporary copies.  */
00db10
-				size_t hostlen = strlen (nhost) + 1;
00db10
-				size_t userlen = strlen (nuser) + 1;
00db10
-				size_t domainlen = strlen (ndomain) + 1;
00db10
+				size_t hostlen = strlen (nhost ?: "") + 1;
00db10
+				size_t userlen = strlen (nuser ?: "") + 1;
00db10
+				size_t domainlen = strlen (ndomain ?: "") + 1;
00db10
 				size_t needed = hostlen + userlen + domainlen;
00db10
 
00db10
 				if (buflen - req->key_len - bufused < needed)
00db10
@@ -226,11 +234,11 @@ addgetnetgrentX (struct database_dyn *db, int fd, request_header *req,
00db10
 				  }
00db10
 
00db10
 				nhost = memcpy (buffer + bufused,
00db10
-						nhost, hostlen);
00db10
+						nhost ?: "", hostlen);
00db10
 				nuser = memcpy ((char *) nhost + hostlen,
00db10
-						nuser, userlen);
00db10
+						nuser ?: "", userlen);
00db10
 				ndomain = memcpy ((char *) nuser + userlen,
00db10
-						  ndomain, domainlen);
00db10
+						  ndomain ?: "", domainlen);
00db10
 			      }
00db10
 
00db10
 			    char *wp = buffer + buffilled;
00db10
diff --git glibc-2.17-c758a686/nscd/nscd_netgroup.c glibc-2.17-c758a686/nscd/nscd_netgroup.c
00db10
index cac4ebf..acb2c81 100644
00db10
--- glibc-2.17-c758a686/nscd/nscd_netgroup.c
00db10
+++ glibc-2.17-c758a686/nscd/nscd_netgroup.c
00db10
@@ -48,7 +48,7 @@ __nscd_setnetgrent (const char *group, struct __netgrent *datap)
00db10
 {
00db10
   int gc_cycle;
00db10
   int nretries = 0;
00db10
-  size_t group_len = strlen (group);
00db10
+  size_t group_len = strlen (group) + 1;
00db10
 
00db10
   /* If the mapping is available, try to search there instead of
00db10
      communicating with the nscd.  */