attr: fix segfault in gitattributes parsing code
authorSteffen Prohaska <prohaska@zib.de>
Thu, 18 Oct 2007 20:02:35 +0000 (22:02 +0200)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 19 Oct 2007 01:11:27 +0000 (21:11 -0400)
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>
attr.c
t/t0020-crlf.sh

diff --git a/attr.c b/attr.c
index 1293993..6e82507 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -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,
index 0807d9f..62bc4bb 100755 (executable)
@@ -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