about summary refs log tree commit diff
path: root/nscd/nscd-client.h
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2014-04-30 12:00:39 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2014-04-30 12:00:39 +0530
commitbc8f194c8c29e46e8ee4034f06e46988dfff38f7 (patch)
treefce0fda2012a3d78d9557afc4a4f5bbe5fa9ee4c /nscd/nscd-client.h
parent1cdeb2372ddecac0dfe0c132a033e9590ffa07d2 (diff)
downloadglibc-bc8f194c8c29e46e8ee4034f06e46988dfff38f7.tar.gz
glibc-bc8f194c8c29e46e8ee4034f06e46988dfff38f7.tar.xz
glibc-bc8f194c8c29e46e8ee4034f06e46988dfff38f7.zip
Initialize all of datahead structure in nscd (BZ #16791)
The datahead structure has an unused padding field that remains
uninitialized.  Valgrind prints out a warning for it on querying a
netgroups entry.  This is harmless, but is a potential data leak since
it would result in writing out an uninitialized byte to the cache
file.  Besides, this happens only when there is a cache miss, so we're
not adding computation to any fast path.
Diffstat (limited to 'nscd/nscd-client.h')
-rw-r--r--nscd/nscd-client.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h
index c069bf6810..ee16df6083 100644
--- a/nscd/nscd-client.h
+++ b/nscd/nscd-client.h
@@ -240,12 +240,17 @@ static inline time_t
 datahead_init_common (struct datahead *head, nscd_ssize_t allocsize,
 		      nscd_ssize_t recsize, uint32_t ttl)
 {
+  /* Initialize so that we don't write out junk in uninitialized data to the
+     cache.  */
+  memset (head, 0, sizeof (*head));
+
   head->allocsize = allocsize;
   head->recsize = recsize;
   head->usable = true;
 
   head->ttl = ttl;
-  /* Compute the timeout time.  */
+
+  /* Compute and return the timeout time.  */
   return head->timeout = time (NULL) + ttl;
 }
 
@@ -253,18 +258,25 @@ static inline time_t
 datahead_init_pos (struct datahead *head, nscd_ssize_t allocsize,
 		   nscd_ssize_t recsize, uint8_t nreloads, uint32_t ttl)
 {
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
+
   head->notfound = false;
   head->nreloads = nreloads;
-  return datahead_init_common (head, allocsize, recsize, ttl);
+
+  return ret;
 }
 
 static inline time_t
 datahead_init_neg (struct datahead *head, nscd_ssize_t allocsize,
 		   nscd_ssize_t recsize, uint32_t ttl)
 {
+  time_t ret = datahead_init_common (head, allocsize, recsize, ttl);
+
+  /* We don't need to touch nreloads here since it is set to our desired value
+     (0) when we clear the structure.  */
   head->notfound = true;
-  head->nreloads = 0;
-  return datahead_init_common (head, allocsize, recsize, ttl);
+
+  return ret;
 }
 
 /* Structure for one hash table entry.  */