trailer: use size_t for string offsets
commit0d2db00e24ee2df4459151c5ba6de9306e30e727
authorJeff King <peff@peff.net>
Thu, 23 Aug 2018 00:44:38 +0000 (22 20:44 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Aug 2018 17:08:51 +0000 (23 10:08 -0700)
tree259ec0db3f8618b12743511fa26875b0dfa72c42
parent53f9a3e157dbbc901a02ac2c73346d375e24978c
trailer: use size_t for string offsets

Many of the string-parsing functions inside trailer.c return
integer offsets into the string (e.g., to point to the end
of the trailer block). Several of these use an "int" to
return or store the offsets. On a system where "size_t" is
much larger than "int" (e.g., most 64-bit ones), it's easy
to feed a gigantic commit message that results in a negative
offset. This can result in us reading memory before the
string (if the int is used as an index) or far after (if
it's implicitly cast to a size_t by passing to a strbuf
function).

Let's fix this by using size_t for all string offsets. Note
that several of the functions need ssize_t, since they use
"-1" as a sentinel value. The interactions here can be
pretty subtle. E.g., end_of_title in find_trailer_start()
does not itself need to be signed, but it is compared to the
result of last_line(), which is. That promotes the latter to
unsigned, and the ">=" does not behave as you might expect.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
trailer.c