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

8 messages from 2006-12-09 to 2006-12-10. Participants: Johannes Schindelin, Junio C Hamano, Nicolas Pitre, Jeff King.
Thread: https://gitlist.dev/t/43213

## Nicolas Pitre, 2006-12-09 03:23

Subject: builtin git-shortlog still broken
Message-ID: <Pine.LNX.4.64.0612082205240.2630@xanadu.home>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0612082205240.2630%40xanadu.home

```
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, 2006-12-09 04:04

Subject: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <20061209040421.GA29113@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20061209040421.GA29113%40coredump.intra.peff.net
In-Reply-To: <Pine.LNX.4.64.0612082205240.2630@xanadu.home>

```
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(-)

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, 2006-12-09 21:56

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <Pine.LNX.4.64.0612091653070.2630@xanadu.home>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0612091653070.2630%40xanadu.home
In-Reply-To: <20061209040421.GA29113@coredump.intra.peff.net>

```
On Fri, 8 Dec 2006, Jeff King wrote:

> 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, 2006-12-09 23:21

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <Pine.LNX.4.63.0612100019270.28348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612100019270.28348%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <20061209040421.GA29113@coredump.intra.peff.net>

```
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

```

## Johannes Schindelin, 2006-12-09 23:34

Subject: Re: builtin git-shortlog still broken
Message-ID: <Pine.LNX.4.63.0612100034010.28348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612100034010.28348%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <Pine.LNX.4.64.0612082205240.2630@xanadu.home>

```
Hi,

On Fri, 8 Dec 2006, 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.

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

```

## Jeff King, 2006-12-10 03:45

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <20061210034524.GA11819@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20061210034524.GA11819%40coredump.intra.peff.net
In-Reply-To: <Pine.LNX.4.63.0612100019270.28348@wbgn013.biozentrum.uni-wuerzburg.de>

```
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.


```

## Junio C Hamano, 2006-12-10 06:01

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <7vejr85lxq.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vejr85lxq.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20061210034524.GA11819@coredump.intra.peff.net>

```
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, 2006-12-10 22:43

Subject: Re: [PATCH] shortlog: fix segfault on empty authorname
Message-ID: <Pine.LNX.4.63.0612102342490.28348@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612102342490.28348%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <20061210034524.GA11819@coredump.intra.peff.net>

```
Hi,

On Sat, 9 Dec 2006, Jeff King wrote:

> 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

```
