<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/path.c, branch v2.16.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.16.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.16.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2017-10-28T01:18:40Z</updated>
<entry>
<title>Merge branch 'ao/path-use-xmalloc'</title>
<updated>2017-10-28T01:18:40Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-10-28T01:18:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=fd052e4f9abc2cf9ea54ea33e2b563c0e120a795'/>
<id>urn:sha1:fd052e4f9abc2cf9ea54ea33e2b563c0e120a795</id>
<content type='text'>
A possible oom error is now caught as a fatal error, instead of
continuing and dereferencing NULL.

* ao/path-use-xmalloc:
  path.c: use xmalloc() in add_to_trie()
</content>
</entry>
<entry>
<title>path.c: use xmalloc() in add_to_trie()</title>
<updated>2017-10-25T07:16:22Z</updated>
<author>
<name>Andrey Okoshkin</name>
<email>a.okoshkin@samsung.com</email>
</author>
<published>2017-10-24T15:15:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=55d7d15847e84d531f712f9fd6a7117283b208a3'/>
<id>urn:sha1:55d7d15847e84d531f712f9fd6a7117283b208a3</id>
<content type='text'>
Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps
and checks memory allocation result.

Signed-off-by: Andrey Okoshkin &lt;a.okoshkin@samsung.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'tg/memfixes'</title>
<updated>2017-10-07T07:27:54Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-10-07T07:27:54Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=98c03a0de83f5b5a98ac25d5639f647559c0e619'/>
<id>urn:sha1:98c03a0de83f5b5a98ac25d5639f647559c0e619</id>
<content type='text'>
Fixes for a handful memory access issues identified by valgrind.

* tg/memfixes:
  sub-process: use child_process.args instead of child_process.argv
  http-push: fix construction of hex value from path
  path.c: fix uninitialized memory access
</content>
</entry>
<entry>
<title>Merge branch 'rs/cleanup-strbuf-users'</title>
<updated>2017-10-05T04:48:19Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-10-05T04:48:19Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e46ebc27547e3d09385a76ade7ab11dc794f7595'/>
<id>urn:sha1:e46ebc27547e3d09385a76ade7ab11dc794f7595</id>
<content type='text'>
Code clean-up.

* rs/cleanup-strbuf-users:
  graph: use strbuf_addchars() to add spaces
  use strbuf_addstr() for adding strings to strbufs
  path: use strbuf_add_real_path()
</content>
</entry>
<entry>
<title>path.c: fix uninitialized memory access</title>
<updated>2017-10-04T04:47:16Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-10-03T23:30:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=8262715b8eb157497ec1ee1cfcef778d526b2336'/>
<id>urn:sha1:8262715b8eb157497ec1ee1cfcef778d526b2336</id>
<content type='text'>
In cleanup_path we're passing in a char array, run a memcmp on it, and
run through it without ever checking if something is in the array in the
first place.  This can lead us to access uninitialized memory, for
example in t5541-http-push-smart.sh test 7, when run under valgrind:

==4423== Conditional jump or move depends on uninitialised value(s)
==4423==    at 0x242FA9: cleanup_path (path.c:35)
==4423==    by 0x242FA9: mkpath (path.c:456)
==4423==    by 0x256CC7: refname_match (refs.c:364)
==4423==    by 0x26C181: count_refspec_match (remote.c:1015)
==4423==    by 0x26C181: match_explicit_lhs (remote.c:1126)
==4423==    by 0x26C181: check_push_refs (remote.c:1409)
==4423==    by 0x2ABB4D: transport_push (transport.c:870)
==4423==    by 0x186703: push_with_options (push.c:332)
==4423==    by 0x18746D: do_push (push.c:409)
==4423==    by 0x18746D: cmd_push (push.c:566)
==4423==    by 0x1183E0: run_builtin (git.c:352)
==4423==    by 0x11973E: handle_builtin (git.c:539)
==4423==    by 0x11973E: run_argv (git.c:593)
==4423==    by 0x11973E: main (git.c:698)
==4423==  Uninitialised value was created by a heap allocation
==4423==    at 0x4C2CD8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4423==    by 0x4C2F195: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4423==    by 0x2C196B: xrealloc (wrapper.c:137)
==4423==    by 0x29A30B: strbuf_grow (strbuf.c:66)
==4423==    by 0x29A30B: strbuf_vaddf (strbuf.c:277)
==4423==    by 0x242F9F: mkpath (path.c:454)
==4423==    by 0x256CC7: refname_match (refs.c:364)
==4423==    by 0x26C181: count_refspec_match (remote.c:1015)
==4423==    by 0x26C181: match_explicit_lhs (remote.c:1126)
==4423==    by 0x26C181: check_push_refs (remote.c:1409)
==4423==    by 0x2ABB4D: transport_push (transport.c:870)
==4423==    by 0x186703: push_with_options (push.c:332)
==4423==    by 0x18746D: do_push (push.c:409)
==4423==    by 0x18746D: cmd_push (push.c:566)
==4423==    by 0x1183E0: run_builtin (git.c:352)
==4423==    by 0x11973E: handle_builtin (git.c:539)
==4423==    by 0x11973E: run_argv (git.c:593)
==4423==    by 0x11973E: main (git.c:698)
==4423==

Avoid this by using skip_prefix(), which knows not to go beyond the
end of the string.

Reported-by: Thomas Gummerer &lt;t.gummerer@gmail.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Reviewed-by: Jonathan Nieder &lt;jrnieder@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jk/validate-headref-fix'</title>
<updated>2017-10-03T06:42:49Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2017-10-03T06:42:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bb3afad386aa2852c2ea86ac50ba33e770ee7efc'/>
<id>urn:sha1:bb3afad386aa2852c2ea86ac50ba33e770ee7efc</id>
<content type='text'>
Code clean-up.

* jk/validate-headref-fix:
  validate_headref: use get_oid_hex for detached HEADs
  validate_headref: use skip_prefix for symref parsing
  validate_headref: NUL-terminate HEAD buffer
</content>
</entry>
<entry>
<title>path: use strbuf_add_real_path()</title>
<updated>2017-10-02T04:13:41Z</updated>
<author>
<name>René Scharfe</name>
<email>l.s.r@web.de</email>
</author>
<published>2017-10-01T14:44:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=fa2bb34477120f18d0834a545ac777e6295650d2'/>
<id>urn:sha1:fa2bb34477120f18d0834a545ac777e6295650d2</id>
<content type='text'>
Avoid a string copy to a static buffer by using strbuf_add_real_path()
instead of combining strbuf_addstr() and real_path().

Patch generated by Coccinelle and contrib/coccinelle/strbuf.cocci.

Signed-off-by: Rene Scharfe &lt;l.s.r@web.de&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>validate_headref: use get_oid_hex for detached HEADs</title>
<updated>2017-09-27T07:07:22Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-09-27T06:17:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0bca165fdb57b032e505161a9450fd5e3edfd19a'/>
<id>urn:sha1:0bca165fdb57b032e505161a9450fd5e3edfd19a</id>
<content type='text'>
If a candidate HEAD isn't a symref, we check that it
contains a viable sha1. But in a post-sha1 world, we should
be checking whether it has any plausible object-id.

We can do that by switching to get_oid_hex().

Note that both before and after this patch, we only check
for a plausible object id at the start of the file, and then
call that good enough.  We ignore any content _after_ the
hex, so a string like:

  0123456789012345678901234567890123456789 foo

is accepted. Though we do put extra bytes like this into
some pseudorefs (e.g., FETCH_HEAD), we don't typically do so
with HEAD. We could tighten this up by using parse_oid_hex(),
like:

  if (!parse_oid_hex(buffer, &amp;oid, &amp;end) &amp;&amp;
      *end++ == '\n' &amp;&amp; *end == '\0')
          return 0;

But we're probably better to remain on the loose side. We're
just checking here for a plausible-looking repository
directory, so heuristics are acceptable (if we really want
to be meticulous, we should use the actual ref code to parse
HEAD).

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>validate_headref: use skip_prefix for symref parsing</title>
<updated>2017-09-27T07:06:31Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-09-27T06:17:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7eb4b9d025e1ac2ed5a49530c614b7e69054625a'/>
<id>urn:sha1:7eb4b9d025e1ac2ed5a49530c614b7e69054625a</id>
<content type='text'>
Since the previous commit guarantees that our symref buffer
is NUL-terminated, we can just use skip_prefix() and friends
to parse it. This is shorter and saves us having to deal
with magic numbers and keeping the "len" counter up to date.

While we're at it, let's name the rather obscure "buf" to
"refname", since that is the thing we are parsing with it.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>validate_headref: NUL-terminate HEAD buffer</title>
<updated>2017-09-27T07:01:24Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-09-27T06:17:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6e68c914102774832c519804498538791cdddff9'/>
<id>urn:sha1:6e68c914102774832c519804498538791cdddff9</id>
<content type='text'>
When we are checking to see if we have a git repo, we peek
into the HEAD file and see if it's a plausible symlink,
symref, or detached HEAD.

For the latter two, we read the contents with read_in_full(),
which means they aren't NUL-terminated. The symref check is
careful to respect the length we got, but the sha1 check
will happily parse up to 40 bytes, even if we read fewer.

E.g.,:

  echo 1234 &gt;.git/HEAD
  git rev-parse

will parse 36 uninitialized bytes from our stack buffer.

This isn't a big deal in practice. Our buffer is 256 bytes,
so we know we'll never read outside of it. The worst case is
that the uninitialized bytes look like valid hex, and we
claim a bogus HEAD file is valid. The chances of this
happening randomly are quite slim, but let's be careful.

One option would be to check that "len == 41" before feeding
the buffer to get_sha1_hex(). But we'd like to eventually
prepare for a world with variable-length hashes. Let's
NUL-terminate as soon as we've read the buffer (we already
even leave a spare byte to do so!). That fixes this problem
without depending on the size of an object id.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
