diff mbox

[2/2] Initialize all of datahead structure in nscd [BZ #16791]

Message ID 20140401164104.GH16484@spoyarek.pnq.redhat.com
State Deferred
Headers show

Commit Message

Siddhesh Poyarekar April 1, 2014, 4:41 p.m. UTC
Hi,

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.

Tested on x86_64 to verify that the valgrind warning is gone with
netgroups.

Siddhesh

	[BZ #16791]
	* nscd/nscd-client.h (datahead_init_common): Initialize unused
	field in datahead.

---
 nscd/nscd-client.h | 2 ++
 1 file changed, 2 insertions(+)

Comments

Roland McGrath April 1, 2014, 6:26 p.m. UTC | #1
If you bzero before explicitly filling fields, does the compiler optimize
to only zeroing the one unused field?  If so, that seems more futureproof.
diff mbox

Patch

diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h
index c069bf6..663fcc5 100644
--- a/nscd/nscd-client.h
+++ b/nscd/nscd-client.h
@@ -243,6 +243,8 @@  datahead_init_common (struct datahead *head, nscd_ssize_t allocsize,
   head->allocsize = allocsize;
   head->recsize = recsize;
   head->usable = true;
+  /* Initialize so that we don't write out a junk byte to the cache.  */
+  head->unused = 0;
 
   head->ttl = ttl;
   /* Compute the timeout time.  */