Re: [PATCH] sha1_name: fix segfault caused by invalid index access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthieu Moy <Matthieu.Moy@xxxxxxx> writes:

> -	if (pos < 0)
> -		pos = -pos - 1;
> -	ce = active_cache[pos];
> -	if (ce_namelen(ce) == namelen &&
> -	    !memcmp(ce->name, filename, namelen))
> +	if (pos >= 0) {
> +		ce = active_cache[pos];

A positive return value of cache_name_pos() is "I found a merged entry
with that name at this index" while a negative is "I would insert at this
index if you give me a merged entry with that name".

The latter is what the name comparison logic is about.  The caller asked
for filename, and the return value may point at an existing entry (in
which case you do not even need to memcmp(), but it doesn't hurt and
simplifies the code).  The nagative one with compensation could be
pointing at an unrelated entry, or an unmerged entry with filename you
asked, which sorts higher than a merged entry with the same name.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]