threads / patch / 43213

patchRe: [PATCH] shortlog: fix segfault on empty authorname

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname

## tl;dr

8 messages between Dec 9, 2006 and Dec 10, 2006. Diffs are folded; open one to read it.

replies: 7people: 4as markdown or json

Nicolas Pitre· Dec 9, 2006, 03:23 UTC · lore

builtin git-shortlog still broken

On the Linux kernel repository, doing "git shortlog v2.6.18.." works fine. "git shortlog v2.6.17.." works fine. "git shortlog v2.6.16.." also works fine. But "git shortlog v2.6.15.." dies with a segmentation fault. Trying "git log v2.6.15.. | git shortlog" also produces the same crash while "git log v2.6.16.. | git shortlog" works fine.

The old perl version doesn't have any such issue with those test cases, not even with the whole kernel history.

Jeff King· Dec 9, 2006, 04:04 UTC · re: Nicolas Pitre · lore

[PATCH] shortlog: fix segfault on empty authorname

The old code looked backwards from the email address to parse the name, allowing an arbitrary number of spaces between the two. However, in the case of no name, we looked back too far to the 'author' (or 'Author:') header. Instead, remove at most one space between name and address.

The bug was triggered by commit febf7ea4bed from linux-2.6.
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin-shortlog.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin-shortlog.c +2 −2
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index f1124e2..7a2ddfe 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -188,7 +188,7 @@ static void read_from_stdin(struct path_list *list)
 				bob = buffer + strlen(buffer);
 			else {
 				offset = 8;
-				while (isspace(bob[-1]))
+				if (isspace(bob[-1]))
 					bob--;
 			}
 
@@ -236,7 +236,7 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
 					author = scratch;
 					authorlen = strlen(scratch);
 				} else {
-					while (bracket[-1] == ' ')
+					if (bracket[-1] == ' ')
 						bracket--;
 
 					author = buffer + 7;
-- 
1.4.4.2.g3528-dirty

On Fri, Dec 08, 2006 at 10:23:14PM -0500, Nicolas Pitre wrote:

> On the Linux kernel repository, doing "git shortlog v2.6.18.." works 
> fine. "git shortlog v2.6.17.." works fine. "git shortlog v2.6.16.." also 
> works fine.  But "git shortlog v2.6.15.." dies with a segmentation 
> fault.  Trying "git log v2.6.15.. | git shortlog" also produces the same 
> crash while "git log v2.6.16.. | git shortlog" works fine.
> 
> The old perl version doesn't have any such issue with those test cases, 
> not even with the whole kernel history.
> 
> 
> Nicolas
> -
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
Nicolas Pitre· Dec 9, 2006, 21:56 UTC · re: Jeff King · lore
On Fri, 8 Dec 2006, Jeff King wrote:
Show 8 quoted lines
> The old code looked backwards from the email address to parse the name,
> allowing an arbitrary number of spaces between the two. However, in the case
> of no name, we looked back too far to the 'author' (or 'Author:') header.
> Instead, remove at most one space between name and address.
> 
> The bug was triggered by commit febf7ea4bed from linux-2.6.
> 
> Signed-off-by: Jeff King <peff@peff.net>
Yep, that fixes the problem.
Johannes Schindelin· Dec 9, 2006, 23:21 UTC · re: Jeff King · lore
Hi,
On Fri, 8 Dec 2006, Jeff King wrote:
> Instead, remove at most one space between name and address.
Why? We can fix it properly: Instead of
> -				while (isspace(bob[-1]))
> +				if (isspace(bob[-1]))
do something like
				while (bob - 1 != buffer + 7 && 
						isspace(bob[-1]))

Ciao, Dscho

Jeff King· Dec 10, 2006, 03:45 UTC · re: Johannes Schindelin · lore
On Sun, Dec 10, 2006 at 12:21:03AM +0100, Johannes Schindelin wrote:
Show 11 quoted lines
> > Instead, remove at most one space between name and address.
> 
> Why? We can fix it properly: Instead of
> 
> > -				while (isspace(bob[-1]))
> > +				if (isspace(bob[-1]))
> 
> do something like
> 
> 				while (bob - 1 != buffer + 7 && 
> 						isspace(bob[-1]))
It doesn't look like there are ever extra spaces to get soaked up in the
kernel or git repositories, but if there is a reason to expect
  Full Name    <user@domain>
then we should probably replace my fix with yours.
Junio C Hamano· Dec 10, 2006, 06:01 UTC · re: Jeff King · lore
Jeff King <peff@peff.net> writes:
> It doesn't look like there are ever extra spaces to get soaked up in the
> kernel or git repositories, but if there is a reason to expect
>   Full Name    <user@domain>
> then we should probably replace my fix with yours.

As far as I know, commit-tree removes the extra space if exists, so your fix would be fine in practice.

People could write crappy replacements of plumbing, and we may end up with names with trailing whitespaces, but with your fix at least that would not make us crash, and it may even be considered a feature -- it would serve as a coalmine canary to detect such a broken alternative program that creates bogus commit objects.

We might want to tighten fsck-objects to warn about them, though. But that is probably rather low priority.

Johannes Schindelin· Dec 10, 2006, 22:43 UTC · re: Jeff King · lore
Hi,
On Sat, 9 Dec 2006, Jeff King wrote:
Show 18 quoted lines
> On Sun, Dec 10, 2006 at 12:21:03AM +0100, Johannes Schindelin wrote:
> 
> > > Instead, remove at most one space between name and address.
> > 
> > Why? We can fix it properly: Instead of
> > 
> > > -				while (isspace(bob[-1]))
> > > +				if (isspace(bob[-1]))
> > 
> > do something like
> > 
> > 				while (bob - 1 != buffer + 7 && 
> > 						isspace(bob[-1]))
> 
> It doesn't look like there are ever extra spaces to get soaked up in the
> kernel or git repositories, but if there is a reason to expect
>   Full Name    <user@domain>
> then we should probably replace my fix with yours.
This is exactly the kind of assumption which led to the bug to begin with.

Ciao, Dscho

Johannes Schindelin· Dec 9, 2006, 23:34 UTC · re: Nicolas Pitre · lore

Re: builtin git-shortlog still broken

Hi,
On Fri, 8 Dec 2006, Nicolas Pitre wrote:
Show 8 quoted lines
> On the Linux kernel repository, doing "git shortlog v2.6.18.." works 
> fine. "git shortlog v2.6.17.." works fine. "git shortlog v2.6.16.." also 
> works fine.  But "git shortlog v2.6.15.." dies with a segmentation 
> fault.  Trying "git log v2.6.15.. | git shortlog" also produces the same 
> crash while "git log v2.6.16.. | git shortlog" works fine.
> 
> The old perl version doesn't have any such issue with those test cases, 
> not even with the whole kernel history.

Yeah, sorry. I assumed that there are enough sanity checks for the author format, but evidently that is/was not the case here.

Ciao, Dscho

← back to recent threads