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>
Jim Meyering committed
Aug 19, 2008 at 20:42 UTC
c8c4450e1949055cb57e32425b125f45f3481742
1 file changed
+1
-1
builtin-log.c
+1
-1
@@ -461,7 +461,7 @@ static int extra_cc_alloc;
461
static void add_header(const char *value)
462
{
463
int len = strlen(value);
464
- while (value[len - 1] == '\n')
464
+ while (len && value[len - 1] == '\n')
465
len--;
466
if (!strncasecmp(value, "to: ", 4)) {
467
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);