Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 2003d1abfa0c20ee77815f0da33e2c1c > files > 211

glibc-2.5-49.el5_5.5.src.rpm

2008-05-10  Ulrich Drepper  <drepper@redhat.com>

	* nscd/cache.c (cache_add): Before returning with failure and this
	is the first use of the record, mark it as unusable.
	* nscd/aicache.c: Don't touch the dataset after cache_add returns
	reporting a failure.
	* nscd/grpcache.c: Likewise
	* nscd/hstcache.c: Likewise.
	* nscd/initgrcache.c: Likewise.
	* nscd/pwdcache.c: Likewise.

--- libc/nscd/aicache.c	10 May 2008 23:23:52 -0000	1.19
+++ libc/nscd/aicache.c	11 May 2008 03:02:54 -0000	1.20
@@ -556,10 +556,8 @@ next_nip:
       /* Now get the lock to safely insert the records.  */
       pthread_rwlock_rdlock (&db->lock);
 
-      if (cache_add (req->type, key_copy, req->key_len, &dataset->head, true,
-		     db, uid) < 0)
-	/* Ensure the data can be recovered.  */
-	dataset->head.usable = false;
+      (void) cache_add (req->type, key_copy, req->key_len, &dataset->head,
+			true, db, uid);
 
       pthread_rwlock_unlock (&db->lock);
 
--- libc/nscd/cache.c	19 Apr 2008 16:41:46 -0000	1.36
+++ libc/nscd/cache.c	11 May 2008 03:02:25 -0000	1.37
@@ -138,7 +138,13 @@ cache_add (int type, const void *key, si
   newp = mempool_alloc (table, sizeof (struct hashentry), 0);
   /* If we cannot allocate memory, just do not do anything.  */
   if (newp == NULL)
-    return -1;
+    {  
+      /* If necessary mark the entry as unusable so that lookups will
+	 not use it.  */
+      if (first)
+	packet->usable = false;
+      return -1;
+    }
 
   newp->type = type;
   newp->first = first;
--- libc/nscd/grpcache.c	19 Apr 2008 16:42:32 -0000	1.51
+++ libc/nscd/grpcache.c	11 May 2008 03:02:54 -0000	1.52
@@ -146,10 +146,8 @@ cache_addgr (struct database_dyn *db, in
 	      /* Now get the lock to safely insert the records.  */
 	      pthread_rwlock_rdlock (&db->lock);
 
-	      if (cache_add (req->type, &dataset->strdata, req->key_len,
-			     &dataset->head, true, db, owner) < 0)
-		/* Ensure the data can be recovered.  */
-		dataset->head.usable = false;
+	      (void) cache_add (req->type, &dataset->strdata, req->key_len,
+				&dataset->head, true, db, owner);
 
 	      pthread_rwlock_unlock (&db->lock);
 
@@ -356,12 +354,7 @@ cache_addgr (struct database_dyn *db, in
 	    {
 	      if (cache_add (GETGRBYGID, cp, key_offset, &dataset->head, true,
 			     db, owner) < 0)
-		{
-		  /* Could not allocate memory.  Make sure the data gets
-		     discarded.  */
-		  dataset->head.usable = false;
-		  goto out;
-		}
+		goto out;
 
 	      first = false;
 	    }
@@ -370,12 +363,7 @@ cache_addgr (struct database_dyn *db, in
 	    {
 	      if (cache_add (GETGRBYNAME, key_copy, key_len + 1,
 			     &dataset->head, true, db, owner) < 0)
-		{
-		  /* Could not allocate memory.  Make sure the data gets
-		     discarded.  */
-		  dataset->head.usable = false;
-		  goto out;
-		}
+		goto out;
 
 	      first = false;
 	    }
@@ -389,12 +377,8 @@ cache_addgr (struct database_dyn *db, in
 	    {
 	      if (req->type == GETGRBYNAME && db->propagate)
 		(void) cache_add (GETGRBYGID, cp, key_offset, &dataset->head,
-				  req->type != GETGRBYNAME, db, owner);
+				  false, db, owner);
 	    }
-	  else if (first)
-	    /* Could not allocate memory.  Make sure the data gets
-	       discarded.  */
-	    dataset->head.usable = false;
 
 	out:
 	  pthread_rwlock_unlock (&db->lock);
--- libc/nscd/hstcache.c	19 Apr 2008 16:42:32 -0000	1.47
+++ libc/nscd/hstcache.c	11 May 2008 03:02:54 -0000	1.48
@@ -155,10 +155,8 @@ cache_addhst (struct database_dyn *db, i
 	      /* Now get the lock to safely insert the records.  */
 	      pthread_rwlock_rdlock (&db->lock);
 
-	      if (cache_add (req->type, &dataset->strdata, req->key_len,
-			     &dataset->head, true, db, owner) < 0)
-		/* Ensure the data can be recovered.  */
-		dataset->head.usable = false;
+	      (void) cache_add (req->type, &dataset->strdata, req->key_len,
+				&dataset->head, true, db, owner);
 
 	      pthread_rwlock_unlock (&db->lock);
 
@@ -409,11 +407,8 @@ cache_addhst (struct database_dyn *db, i
 		  || req->type == GETHOSTBYADDR
 		  || req->type == GETHOSTBYADDRv6);
 
-	  if (cache_add (req->type, key_copy, req->key_len,
-			 &dataset->head, true, db, owner) < 0)
-	    /* Could not allocate memory.  Make sure the
-	       data gets discarded.  */
-	    dataset->head.usable = false;
+	  (void) cache_add (req->type, key_copy, req->key_len,
+			    &dataset->head, true, db, owner);
 
 	  pthread_rwlock_unlock (&db->lock);
 	}
--- libc/nscd/initgrcache.c	19 Apr 2008 16:42:32 -0000	1.13
+++ libc/nscd/initgrcache.c	11 May 2008 03:02:54 -0000	1.14
@@ -230,10 +230,8 @@ addinitgroupsX (struct database_dyn *db,
 	      /* Now get the lock to safely insert the records.  */
 	      pthread_rwlock_rdlock (&db->lock);
 
-	      if (cache_add (req->type, key_copy, req->key_len,
-			     &dataset->head, true, db, uid) < 0)
-		/* Ensure the data can be recovered.  */
-		dataset->head.usable = false;
+	      (void) cache_add (req->type, key_copy, req->key_len,
+				&dataset->head, true, db, uid);
 
 	      pthread_rwlock_unlock (&db->lock);
 
@@ -399,11 +397,8 @@ addinitgroupsX (struct database_dyn *db,
 	  /* Now get the lock to safely insert the records.  */
 	  pthread_rwlock_rdlock (&db->lock);
 
-	  if (cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true,
-			 db, uid) < 0)
-	    /* Could not allocate memory.  Make sure the data gets
-	       discarded.  */
-	    dataset->head.usable = false;
+	  (void) cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true,
+			    db, uid);
 
 	  pthread_rwlock_unlock (&db->lock);
 	}
--- libc/nscd/pwdcache.c	19 Apr 2008 16:42:32 -0000	1.49
+++ libc/nscd/pwdcache.c	11 May 2008 03:02:54 -0000	1.50
@@ -153,11 +153,8 @@ cache_addpw (struct database_dyn *db, in
 	      /* Now get the lock to safely insert the records.  */
 	      pthread_rwlock_rdlock (&db->lock);
 
-	      if (cache_add (req->type, key_copy, req->key_len,
-			     &dataset->head, true, db, owner) < 0)
-		/* Ensure the data can be recovered.  */
-		dataset->head.usable = false;
-
+	      (void) cache_add (req->type, key_copy, req->key_len,
+				&dataset->head, true, db, owner);
 
 	      pthread_rwlock_unlock (&db->lock);
 
@@ -352,12 +349,7 @@ cache_addpw (struct database_dyn *db, in
 	    {
 	      if (cache_add (GETPWBYUID, cp, key_offset, &dataset->head, true,
 			     db, owner) < 0)
-		{
-		  /* Could not allocate memory.  Make sure the data gets
-		     discarded.  */
-		  dataset->head.usable = false;
-		  goto out;
-		}
+		goto out;
 
 	      first = false;
 	    }
@@ -366,12 +358,7 @@ cache_addpw (struct database_dyn *db, in
 	    {
 	      if (cache_add (GETPWBYNAME, key_copy, key_len + 1,
 			     &dataset->head, true, db, owner) < 0)
-		{
-		  /* Could not allocate memory.  Make sure the data gets
-		     discarded.  */
-		  dataset->head.usable = false;
-		  goto out;
-		}
+		goto out;
 
 	      first = false;
 	    }
@@ -384,12 +371,8 @@ cache_addpw (struct database_dyn *db, in
 	    {
 	      if (req->type == GETPWBYNAME && db->propagate)
 		(void) cache_add (GETPWBYUID, cp, key_offset, &dataset->head,
-				  req->type != GETPWBYNAME, db, owner);
+				  false, db, owner);
 	    }
-	  else if (first)
-	    /* Could not allocate memory.  Make sure the data gets
-	       discarded.  */
-	    dataset->head.usable = false;
 
 	out:
 	  pthread_rwlock_unlock (&db->lock);