Skip to content

Commit

Permalink
attr: fix segfault in gitattributes parsing code
Browse files Browse the repository at this point in the history
git may segfault if gitattributes contains an invalid
entry. A test is added to t0020 that triggers the segfault.
The parsing code is fixed to avoid the crash.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Steffen Prohaska authored and Shawn O. Pearce committed Oct 19, 2007
1 parent 415e7b8 commit d7b0a09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
num_attr = 0;
cp = name + namelen;
cp = cp + strspn(cp, blank);
while (*cp)
while (*cp) {
cp = parse_attr(src, lineno, cp, &num_attr, res);
if (!cp)
return NULL;
}
if (pass)
break;
res = xcalloc(1,
Expand Down
7 changes: 7 additions & 0 deletions t/t0020-crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,11 @@ test_expect_success 'in-tree .gitattributes (4)' '
}
'

test_expect_success 'invalid .gitattributes (must not crash)' '
echo "three +crlf" >>.gitattributes &&
git diff
'

test_done

0 comments on commit d7b0a09

Please sign in to comment.