Revision b897bf5f37f81d6a9303c4542422cf33d08b7cf0 authored by Jeff King on 23 June 2020, 15:24:49 UTC, committed by Junio C Hamano on 24 June 2020, 02:56:26 UTC
Our anonymize_mem() function is careful to take a ptr/len pair to allow storing binary tokens like object ids, as well as partial strings (e.g., just "foo" of "foo/bar"). But it duplicates the hash key using xstrdup()! That means that: - for a partial string, we'd store all bytes up to the NUL, even though we'd never look at anything past "len". This didn't produce wrong behavior, but was wasteful. - for a binary oid that doesn't contain a zero byte, we'd copy garbage bytes off the end of the array (though as long as nothing complained about reading uninitialized bytes, further reads would be limited by "len", and we'd produce the correct results) - for a binary oid that does contain a zero byte, we'd copy _fewer_ bytes than intended into the hashmap struct. When we later try to look up a value, we'd access uninitialized memory and potentially falsely claim that a particular oid is not present. The most common reason to store an oid is an anonymized gitlink, but our test case doesn't have any gitlinks at all. So let's add one whose oid contains a NUL and is present at two different paths. ASan catches the memory error, but even without it we can detect the bug because the oid is not anonymized the same way for both paths. And of course the fix is to copy the correct number of bytes. We don't technically need the appended NUL from xmemdupz(), but it doesn't hurt as an extra protection against anybody treating it like a string (plus a future patch will push us more in that direction). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b8c0689
File | Mode | Size |
---|---|---|
xdiff.h | -rw-r--r-- | 3.7 KB |
xdiffi.c | -rw-r--r-- | 27.1 KB |
xdiffi.h | -rw-r--r-- | 1.9 KB |
xemit.c | -rw-r--r-- | 7.9 KB |
xemit.h | -rw-r--r-- | 1.2 KB |
xhistogram.c | -rw-r--r-- | 9.4 KB |
xinclude.h | -rw-r--r-- | 1.1 KB |
xmacros.h | -rw-r--r-- | 1.9 KB |
xmerge.c | -rw-r--r-- | 17.0 KB |
xpatience.c | -rw-r--r-- | 10.5 KB |
xprepare.c | -rw-r--r-- | 12.0 KB |
xprepare.h | -rw-r--r-- | 1.0 KB |
xtypes.h | -rw-r--r-- | 1.5 KB |
xutils.c | -rw-r--r-- | 9.6 KB |
xutils.h | -rw-r--r-- | 1.7 KB |
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...