List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] cache: don't leave cache_slot fields uninitialized
@ 2014-01-12 16:49 john
  2014-01-12 18:32 ` Jason
  2014-01-12 19:02 ` Jason
  0 siblings, 2 replies; 3+ messages in thread
From: john @ 2014-01-12 16:49 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] cache: don't leave cache_slot fields uninitialized
  2014-01-12 16:49 [PATCH] cache: don't leave cache_slot fields uninitialized john
@ 2014-01-12 18:32 ` Jason
  2014-01-12 19:02 ` Jason
  1 sibling, 0 replies; 3+ messages in thread
From: Jason @ 2014-01-12 18:32 UTC (permalink / raw)


Merged, thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] cache: don't leave cache_slot fields uninitialized
  2014-01-12 16:49 [PATCH] cache: don't leave cache_slot fields uninitialized john
  2014-01-12 18:32 ` Jason
@ 2014-01-12 19:02 ` Jason
  1 sibling, 0 replies; 3+ messages in thread
From: Jason @ 2014-01-12 19:02 UTC (permalink / raw)


On Sun, Jan 12, 2014 at 5:49 PM, John Keeping <john at keeping.me.uk> wrote:
> 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.

Merged. Sorry for the delay with this.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-12 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-12 16:49 [PATCH] cache: don't leave cache_slot fields uninitialized john
2014-01-12 18:32 ` Jason
2014-01-12 19:02 ` Jason

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).