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