Skip to content

Commit

Permalink
mailinfo: avoid violating strbuf assertion
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Aug 20, 2008
1 parent c8c4450 commit e9d7d10
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin-mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void handle_from(const struct strbuf *from)
el = strcspn(at, " \n\t\r\v\f>");
strbuf_reset(&email);
strbuf_add(&email, at, el);
strbuf_remove(&f, at - f.buf, el + 1);
strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));

/* The remainder is name. It could be "John Doe <john.doe@xz>"
* or "john.doe@xz (John Doe)", but we have removed the
Expand Down
11 changes: 11 additions & 0 deletions t/t5100-mailinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ test_expect_success 'Preserve NULs out of MIME encoded message' '
'

test_expect_success 'mailinfo on from header without name works' '
mkdir info-from &&
git mailsplit -oinfo-from "$TEST_DIRECTORY"/t5100/info-from.in &&
test_cmp "$TEST_DIRECTORY"/t5100/info-from.in info-from/0001 &&
git mailinfo info-from/msg info-from/patch \
<info-from/0001 >info-from/out &&
test_cmp "$TEST_DIRECTORY"/t5100/info-from.expect info-from/out
'

test_done
5 changes: 5 additions & 0 deletions t/t5100/info-from.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Author: [email protected]
Email: [email protected]
Subject: testing bare address in from header
Date: Sun, 25 May 2008 00:38:18 -0700

8 changes: 8 additions & 0 deletions t/t5100/info-from.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
From 667d8940e719cddee1cfe237cbbe215e20270b09 Mon Sep 17 00:00:00 2001
From: [email protected]
Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] testing bare address in from header

commit message
---
patch

0 comments on commit e9d7d10

Please sign in to comment.