{"thread":{"id":"10367","subject":"[PATCH] attr: fix segfault in gitattributes parsing code","startedAt":"2007-10-18T20:02:35Z","lastAt":"2007-10-18T20:02:35Z","messageCount":1,"participants":["Steffen Prohaska"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56426","messageId":"11927377551318-git-send-email-prohaska@zib.de","threadId":"10367","inReplyTo":null,"subject":"[PATCH] attr: fix segfault in gitattributes parsing code","fromName":"Steffen Prohaska","fromEmail":"prohaska@zib.de","sentAt":"2007-10-18T20:02:35Z","receivedAt":"2007-10-18T20:02:35Z","isPatch":true,"sender":{"key":"prohaska@zib.de","avatar":"https://avatars.githubusercontent.com/u/217580?v=4"},"body":"git may segfault if gitattributes contains an invalid\nentry. A test is added to t0020 that triggers the segfault.\nThe parsing code is fixed to avoid the crash.\n\nSigned-off-by: Steffen Prohaska <prohaska@zib.de>\n---\n attr.c          |    5 ++++-\n t/t0020-crlf.sh |    7 +++++++\n 2 files changed, 11 insertions(+), 1 deletions(-)\n\ndiff --git a/attr.c b/attr.c\nindex 92704a3..741db3b 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -209,8 +209,11 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,\n \t\tnum_attr = 0;\n \t\tcp = name + namelen;\n \t\tcp = cp + strspn(cp, blank);\n-\t\twhile (*cp)\n+\t\twhile (*cp) {\n \t\t\tcp = parse_attr(src, lineno, cp, &num_attr, res);\n+\t\t\tif (!cp)\n+\t\t\t\treturn NULL;\n+\t\t}\n \t\tif (pass)\n \t\t\tbreak;\n \t\tres = xcalloc(1,\ndiff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh\nindex 0807d9f..62bc4bb 100755\n--- a/t/t0020-crlf.sh\n+++ b/t/t0020-crlf.sh\n@@ -371,4 +371,11 @@ test_expect_success 'in-tree .gitattributes (4)' '\n \t}\n '\n \n+test_expect_success 'invalid .gitattributes (must not crash)' '\n+\n+\techo \"three +crlf\" >>.gitattributes &&\n+\tgit diff\n+\n+'\n+\n test_done\n-- \n1.5.3.4.1261.g626eb\n"}]}