mirror of
https://git.zx2c4.com/cgit
synced 2024-11-22 08:28:42 +00:00
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>
This commit is contained in:
parent
3fbfced740
commit
33bc949a1e
1
cache.c
1
cache.c
@ -61,6 +61,7 @@ static int open_slot(struct cache_slot *slot)
|
|||||||
if (bufz)
|
if (bufz)
|
||||||
bufkeylen = bufz - slot->buf;
|
bufkeylen = bufz - slot->buf;
|
||||||
|
|
||||||
|
if (slot->key)
|
||||||
slot->match = bufkeylen == slot->keylen &&
|
slot->match = bufkeylen == slot->keylen &&
|
||||||
!memcmp(slot->key, slot->buf, bufkeylen + 1);
|
!memcmp(slot->key, slot->buf, bufkeylen + 1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user