Skip to contentSkip to conversation

attr: fix segfault in gitattributes parsing code

PATCH New Steffen Prohaska 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 attr.c          |    5 ++++-
 t/t0020-crlf.sh |    7 +++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
attr.c +4 -1
index 92704a3..741db3b 100644
@@ -209,8 +209,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,
t/t0020-crlf.sh +7 -0
index 0807d9f..62bc4bb 100755
@@ -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
Signature · 1 line
1.5.3.4.1261.g626eb