@matheusbsbs / matheus-bagliano / commits / e9d7d10a7f
Fork 0

mailinfo: avoid violating strbuf assertion

In handle_from, we calculate the end boundary of a section to remove from a strbuf using strcspn like this: el = strcspn(buf, set_of_end_boundaries); strbuf_remove(&sb, start, el + 1); This works fine if "el" is the offset of the boundary character, meaning we remove up to and including that character. But if the end boundary didn't match (that is, we hit the end of the string as the boundary instead) then we want just "el". Asking for "el+1" caught an out-of-bounds assertion in the strbuf library. This manifested itself when we got a 'From' header that had just an email address with nothing else in it (the end of the string was the end of the address, rather than, e.g., a trailing '>' character), causing git-mailinfo to barf. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 19, 2008 at 13:28 UTC e9d7d10a7f17fb9cc6a4d37b6fdf27170f4deede
4 files changed +25 -1
builtin-mailinfo.c
+1 -1
@@ -107,7 +107,7 @@ static void handle_from(const struct strbuf *from)
107 el = strcspn(at, " \n\t\r\v\f>");
108 strbuf_reset(&email);
109 strbuf_add(&email, at, el);
110 - strbuf_remove(&f, at - f.buf, el + 1);
110 + strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
111
112 /* The remainder is name. It could be "John Doe <john.doe@xz>"
113 * or "john.doe@xz (John Doe)", but we have removed the
t/t5100-mailinfo.sh
+11
@@ -43,4 +43,15 @@ test_expect_success 'Preserve NULs out of MIME encoded message' '
43
44 '
45
46 +test_expect_success 'mailinfo on from header without name works' '
47 +
48 + mkdir info-from &&
49 + git mailsplit -oinfo-from "$TEST_DIRECTORY"/t5100/info-from.in &&
50 + test_cmp "$TEST_DIRECTORY"/t5100/info-from.in info-from/0001 &&
51 + git mailinfo info-from/msg info-from/patch \
52 + <info-from/0001 >info-from/out &&
53 + test_cmp "$TEST_DIRECTORY"/t5100/info-from.expect info-from/out
54 +
55 +'
56 +
57 test_done
t/t5100/info-from.expect new
+5
@@ -0,0 +1,5 @@
1 +Author: bare@example.com
2 +Email: bare@example.com
3 +Subject: testing bare address in from header
4 +Date: Sun, 25 May 2008 00:38:18 -0700
5 +
t/t5100/info-from.in new
+8
@@ -0,0 +1,8 @@
1 +From 667d8940e719cddee1cfe237cbbe215e20270b09 Mon Sep 17 00:00:00 2001
2 +From: bare@example.com
3 +Date: Sun, 25 May 2008 00:38:18 -0700
4 +Subject: [PATCH] testing bare address in from header
5 +
6 +commit message
7 +---
8 +patch