attr: fix segfault in gitattributes parsing code
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>
This commit is contained in:
parent
415e7b877c
commit
d7b0a09316
5
attr.c
5
attr.c
@ -214,8 +214,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
|
|||||||
num_attr = 0;
|
num_attr = 0;
|
||||||
cp = name + namelen;
|
cp = name + namelen;
|
||||||
cp = cp + strspn(cp, blank);
|
cp = cp + strspn(cp, blank);
|
||||||
while (*cp)
|
while (*cp) {
|
||||||
cp = parse_attr(src, lineno, cp, &num_attr, res);
|
cp = parse_attr(src, lineno, cp, &num_attr, res);
|
||||||
|
if (!cp)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
if (pass)
|
if (pass)
|
||||||
break;
|
break;
|
||||||
res = xcalloc(1,
|
res = xcalloc(1,
|
||||||
|
@ -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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user