947208b725
We assume that if setup_traverse_info() is passed a non-empty "base"
string, that string is pointing into a tree object and we can read the
object oid by skipping past the trailing NUL.
As it turns out, this is not true for either of the two calls, and we
may end up reading garbage bytes:
1. In git-merge-tree, our base string is either empty (in which case
we'd never run this code), or it comes from our traverse_path()
helper. The latter overallocates a buffer by the_hash_algo->rawsz
bytes, but then fills it with only make_traverse_path(), leaving
those extra bytes uninitialized (but part of a legitimate heap
buffer).
2. In unpack_trees(), we pass o->prefix, which is some arbitrary
string from the caller. In "git read-tree --prefix=foo", for
instance, it will point to the command-line parameter, and we'll
read 20 bytes past the end of the string.
Interestingly, tools like ASan do not detect (2) because the process
argv is part of a big pre-allocated buffer. So we're reading trash, but
it's trash that's probably part of the next argument, or the
environment.
You can convince it to fail by putting something like this at the
beginning of common-main.c's main() function:
{
int i;
for (i = 0; i < argc; i++)
argv[i] = xstrdup_or_null(argv[i]);
}
That puts the arguments into their own heap buffers, so running:
make SANITIZE=address test
will find problems when "read-tree --prefix" is used (e.g., in t3030).
Doubly interesting, even with the hackery above, this does not fail
prior to
|
||
---|---|---|
.. | ||
.gitignore | ||
api-allocation-growing.txt | ||
api-argv-array.txt | ||
api-config.txt | ||
api-credentials.txt | ||
api-diff.txt | ||
api-directory-listing.txt | ||
api-error-handling.txt | ||
api-gitattributes.txt | ||
api-grep.txt | ||
api-history-graph.txt | ||
api-index-skel.txt | ||
api-index.sh | ||
api-merge.txt | ||
api-object-access.txt | ||
api-oid-array.txt | ||
api-parse-options.txt | ||
api-quote.txt | ||
api-ref-iteration.txt | ||
api-remote.txt | ||
api-revision-walking.txt | ||
api-run-command.txt | ||
api-setup.txt | ||
api-sigchain.txt | ||
api-submodule-config.txt | ||
api-trace2.txt | ||
api-trace.txt | ||
api-tree-walking.txt | ||
api-xdiff-interface.txt | ||
bitmap-format.txt | ||
commit-graph-format.txt | ||
commit-graph.txt | ||
directory-rename-detection.txt | ||
hash-function-transition.txt | ||
http-protocol.txt | ||
index-format.txt | ||
long-running-process-protocol.txt | ||
multi-pack-index.txt | ||
pack-format.txt | ||
pack-heuristics.txt | ||
pack-protocol.txt | ||
partial-clone.txt | ||
protocol-capabilities.txt | ||
protocol-common.txt | ||
protocol-v2.txt | ||
racy-git.txt | ||
repository-version.txt | ||
rerere.txt | ||
send-pack-pipeline.txt | ||
shallow.txt | ||
signature-format.txt | ||
trivial-merge.txt |