about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2016-01-16 11:03:07 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2016-01-17 17:05:39 +0100
commit33bc949a1e927e14479568518bd92e70998e25f8 (patch)
tree4b31bd761caeea599aad3dad07d39341a900a112
parentcache: use size_t for string lengths (diff)
downloadcgit-pink-33bc949a1e927e14479568518bd92e70998e25f8.tar.gz
cgit-pink-33bc949a1e927e14479568518bd92e70998e25f8.zip
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>
-rw-r--r--cache.c5
1 files 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;
 }
d> 2020-07-14Add CGI upload program for temp.causal.agencyJune McEnroe 2020-07-10Add The Broken KingdomsJune McEnroe 2020-07-08Add facebook and twitter to title user-agentJune McEnroe This fixes fetching tweets again! https://github.com/thelounge/thelounge/pull/ 3602 (Intentionally breaking the link so GitHub doesn't add a "referenced this PR" thing?) 2020-06-30Tweak causal.agency for mostly no reasonJune McEnroe 2020-06-30Add Ancillary JusticeJune McEnroe 2020-06-26Add password non-manager to planJune McEnroe I've had this idea for years... 2020-06-26Tweak TF2 sensitivities once moreJune McEnroe 2020-06-19Add note about litterbox bot useJune McEnroe 2020-06-19Publish "IRC suite"June McEnroe 2020-06-17Add errors to link.shJune McEnroe