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>
Steffen Prohaska committed
Oct 18, 2007 at 22:02 UTC
d7b0a09316fe8dcb62ad247dbbb45c3c777667ad
2 files changed
+11
-1
attr.c
+4
-1
@@ -214,8 +214,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
214
num_attr = 0;
215
cp = name + namelen;
216
cp = cp + strspn(cp, blank);
217
- while (*cp)
217
+ while (*cp) {
218
cp = parse_attr(src, lineno, cp, &num_attr, res);
219
+ if (!cp)
220
+ return NULL;
221
+ }
222
if (pass)
223
break;
224
res = xcalloc(1,
t/t0020-crlf.sh
+7
@@ -371,4 +371,11 @@ test_expect_success 'in-tree .gitattributes (4)' '
371
}
372
'
373
374
+test_expect_success 'invalid .gitattributes (must not crash)' '
375
+
376
+ echo "three +crlf" >>.gitattributes &&
377
+ git diff
378
+
379
+'
380
+
381
test_done