git-commit-vandalism/Documentation/technical
Jeff King 947208b725 setup_traverse_info(): stop copying oid
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 ea82b2a085 (tree-walk: store object_id in a separate member,
2019-01-15). That commit switched setup_traverse_info() to actually
copying the hash, rather than simply pointing to it. That pointer was
always pointing to garbage memory, but that commit started actually
dereferencing the bytes, which is what triggers ASan.

That also implies that nobody actually cares about reading these oid
bytes anyway (or at least no path covered by our tests). And manual
inspection of the code backs that up (I'll follow this patch with some
cleanups that show definitively this is the case, but they're quite
invasive, so it's worth doing this fix on its own).

So let's drop the bogus hashcpy(), along with the confusing oversizing
in merge-tree.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-07-31 13:30:58 -07:00
..
.gitignore
api-allocation-growing.txt
api-argv-array.txt api-argv-array.txt: remove broken link to string-list API 2017-10-06 21:16:03 +09:00
api-config.txt Documentation/technical/api-config.txt: fix formatting 2019-04-01 15:17:47 +09:00
api-credentials.txt
api-diff.txt diff.c: remove implicit dependency on the_index 2018-09-21 09:48:10 -07:00
api-directory-listing.txt Documentation: spelling and grammar fixes 2018-06-22 14:26:23 -07:00
api-error-handling.txt
api-gitattributes.txt Documentation: spelling and grammar fixes 2018-06-22 14:26:23 -07:00
api-grep.txt
api-history-graph.txt docs: graph: remove unnecessary `graph_update()' call 2018-10-07 10:10:49 +09:00
api-index-skel.txt
api-index.sh
api-merge.txt
api-object-access.txt sha1_file.c: rename to use dash in file name 2018-04-11 18:11:00 +09:00
api-oid-array.txt sha1-array: provide oid_array_filter 2018-12-05 11:42:31 +09:00
api-parse-options.txt parse-options: make OPT_ARGUMENT() more useful 2019-03-18 11:44:14 +09:00
api-quote.txt
api-ref-iteration.txt refs: remove dead for_each_*_submodule() 2017-08-24 14:56:28 -07:00
api-remote.txt
api-revision-walking.txt revision.c: remove implicit dependency on the_index 2018-09-21 09:51:19 -07:00
api-run-command.txt
api-setup.txt
api-sigchain.txt Fix typos in the documentation 2011-01-04 11:23:42 -08:00
api-submodule-config.txt Merge branch 'sb/submodule-move-nested' 2018-05-08 15:59:17 +09:00
api-trace2.txt trace2: correct trace2 field name documentation 2019-07-09 16:28:40 -07:00
api-trace.txt
api-tree-walking.txt setup_traverse_info(): stop copying oid 2019-07-31 13:30:58 -07:00
api-xdiff-interface.txt
bitmap-format.txt
commit-graph-format.txt commit-graph: rename "large edges" to "extra edges" 2019-01-22 11:33:46 -08:00
commit-graph.txt commit-graph: remove Future Work section 2019-06-12 11:20:53 -07:00
directory-rename-detection.txt Merge branch 'ja/dir-rename-doc-markup-fix' 2019-04-10 02:14:21 +09:00
hash-function-transition.txt doc hash-function-transition: pick SHA-256 as NewHash 2018-08-07 07:40:43 -07:00
http-protocol.txt doc: fix want-capability separator 2018-07-30 11:25:20 -07:00
index-format.txt ieot: add Index Entry Offset Table (IEOT) extension 2018-10-11 15:32:48 +09:00
long-running-process-protocol.txt Docs: split out long-running subprocess handshake 2018-01-25 11:24:32 -08:00
multi-pack-index.txt multi-pack-index: add design document 2018-07-12 13:55:02 -07:00
pack-format.txt midx: write object offsets 2018-07-20 11:27:28 -07:00
pack-heuristics.txt
pack-protocol.txt fix pack protocol example client/server communication 2019-03-18 14:37:54 +09:00
partial-clone.txt partial-clone: add missing 'is' in doc 2019-01-14 11:06:47 -08:00
protocol-capabilities.txt protocol-capabilities.txt: document symref 2019-02-21 12:05:52 -08:00
protocol-common.txt
protocol-v2.txt Documentation/technical/protocol-v2.txt: fix formatting 2019-04-01 15:17:47 +09:00
racy-git.txt
repository-version.txt doc: move extensions.worktreeConfig to the right place 2018-11-16 14:10:31 +09:00
rerere.txt rerere: mention caveat about unmatched conflict markers 2018-08-29 08:54:11 -07:00
send-pack-pipeline.txt
shallow.txt technical/shallow: describe why shallow cannot use replace refs 2018-04-30 11:12:31 +09:00
signature-format.txt
trivial-merge.txt treewide: correct several "up-to-date" to "up to date" 2017-08-23 12:17:22 -07:00