List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH 3/3] cache: don't check for match with no key
Date: Sat, 16 Jan 2016 11:03:07 +0000	[thread overview]
Message-ID: <d31840385a594692e2e74068415fb6ad965e27f7.1452942146.git.john@keeping.me.uk> (raw)
In-Reply-To: <cover.1452942146.git.john@keeping.me.uk>

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 at keeping.me.uk>
---
 cache.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/cache.c b/cache.c
index df1b4a3..6736a01 100644
--- a/cache.c
+++ b/cache.c
@@ -61,8 +61,9 @@ static int open_slot(struct cache_slot *slot)
 	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;
 }
-- 
2.7.0.226.gfe986fe



  parent reply	other threads:[~2016-01-16 11:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-16 11:03 [PATCH 0/3] Fix some issues found by Coverity john
2016-01-16 11:03 ` [PATCH 1/3] ui-log: handle parse_commit() errors john
2016-01-16 11:03 ` [PATCH 2/3] cache: use size_t for string lengths john
2016-01-16 11:03 ` john [this message]
2016-01-17 16:04 ` [PATCH 0/3] Fix some issues found by Coverity Jason
2016-01-17 16:19   ` Jason
2016-01-17 20:25     ` john
2016-02-03  4:46       ` mathstuf
2016-02-08 13:35         ` Jason
2016-02-08 14:16           ` john
2016-02-08 14:33             ` Jason
2016-02-08 16:31               ` john
2016-02-08 17:26                 ` 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=d31840385a594692e2e74068415fb6ad965e27f7.1452942146.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).