List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH] cache: don't leave cache_slot fields uninitialized
Date: Sun, 12 Jan 2014 16:49:40 +0000	[thread overview]
Message-ID: <15cb537a54d999d9ec5720062443928d73b67fa9.1389545326.git.john@keeping.me.uk> (raw)

Valgrind says:

==18344== Conditional jump or move depends on uninitialised value(s)
==18344==    at 0x406C83: open_slot (cache.c:63)
==18344==    by 0x407478: cache_ls (cache.c:403)
==18344==    by 0x404C9A: process_request (cgit.c:639)
==18344==    by 0x406BD2: fill_slot (cache.c:190)
==18344==    by 0x4071A0: cache_process (cache.c:284)
==18344==    by 0x404461: main (cgit.c:952)
==18344==  Uninitialised value was created by a stack allocation
==18344==    at 0x40738B: cache_ls (cache.c:375)

This is caused by the keylen field being used to calculate whether or
not a slot is matched.  We never then check the value of this and the
length of data read depends on the key length read from the file so this
isn't dangerous, but it's nice to avoid branching based on uninitialized
data.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
Is there any chance of getting jk/valgrind-tests merged as well?  It's
been sat there for a while now and is quite useful.

 cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cache.c b/cache.c
index d339435..fa83ddc 100644
--- a/cache.c
+++ b/cache.c
@@ -376,7 +376,7 @@ int cache_ls(const char *path)
 	DIR *dir;
 	struct dirent *ent;
 	int err = 0;
-	struct cache_slot slot;
+	struct cache_slot slot = { 0 };
 	struct strbuf fullname = STRBUF_INIT;
 	size_t prefixlen;
 
-- 
1.8.5.226.g0d60d77



             reply	other threads:[~2014-01-12 16:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-12 16:49 john [this message]
2014-01-12 18:32 ` Jason
2014-01-12 19:02 ` Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15cb537a54d999d9ec5720062443928d73b67fa9.1389545326.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).