git format-patch: avoid underrun when format.headers is empty or all NLs

* builtin-log.c (add_header): Avoid a buffer underrun when
format.headers is empty or all newlines.  Reproduce with this:
git config format.headers '' && git format-patch -1

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jim Meyering 2008-08-19 20:42:04 +02:00 committed by Junio C Hamano
parent 26e08a0190
commit c8c4450e19

View File

@ -461,7 +461,7 @@ static int extra_cc_alloc;
static void add_header(const char *value) static void add_header(const char *value)
{ {
int len = strlen(value); int len = strlen(value);
while (value[len - 1] == '\n') while (len && value[len - 1] == '\n')
len--; len--;
if (!strncasecmp(value, "to: ", 4)) { if (!strncasecmp(value, "to: ", 4)) {
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc); ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);