hash-object --literally: fix buffer overrun with extra-long object type
commit0c3db67cc8137cebea5b1a9c3c7fc379ef8ffda6
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 4 May 2015 07:25:15 +0000 (4 03:25 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 May 2015 17:14:18 +0000 (5 10:14 -0700)
tree82a7a5ae13d5bd50f77e5bfbc0d4590b9b0873b6
parent83115ac4a811ef37318bc0e68a5e8b229751a88f
hash-object --literally: fix buffer overrun with extra-long object type

"hash-object" learned in 5ba9a93 (hash-object: add --literally
option, 2014-09-11) to allow crafting a corrupt/broken object of
unknown type.

When the user-provided type is particularly long, however, it can
overflow the relatively small stack-based character array handed to
write_sha1_file_prepare() by hash_sha1_file() and write_sha1_file(),
leading to stack corruption (and crash).  Introduce a custom helper
to allow arbitrarily long typenames just for "hash-object --literally".

[jc: Eric's original used a strbuf in the more common codepaths, and
I rewrote it to avoid penalizing the non-literally code. Bugs are mine]

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/hash-object.c
cache.h
sha1_file.c