all repos — cgit @ 33bc949a1e927e14479568518bd92e70998e25f8

a hyperfast web frontend for git written in c

cache: don't check for match with no key

We call open_slot() from cache_ls() without a key since we simply want
to read the path out of the header.  Should the file happen to contain
an empty key then we end up calling memcmp() with NULL and a non-zero
length.  Fix this by assigning slot->match only if a key is set, which
is always will be in the code paths where we use slot->match.

Coverity-id: 13807
Signed-off-by: John Keeping <john@keeping.me.uk>
John Keeping john@keeping.me.uk
Sat, 16 Jan 2016 11:03:07 +0000
commit

33bc949a1e927e14479568518bd92e70998e25f8

parent

3fbfced7401cfcbb8006a9a6ce4add6b37a41a55

1 files changed, 3 insertions(+), 2 deletions(-)

jump to
M cache.ccache.c

@@ -61,8 +61,9 @@ bufz = memchr(slot->buf, 0, slot->bufsize);

if (bufz) bufkeylen = bufz - slot->buf; - slot->match = bufkeylen == slot->keylen && - !memcmp(slot->key, slot->buf, bufkeylen + 1); + if (slot->key) + slot->match = bufkeylen == slot->keylen && + !memcmp(slot->key, slot->buf, bufkeylen + 1); return 0; }