{"thread":{"id":"11621","subject":"[PATCH] parse_commit_buffer: don't parse invalid commits","startedAt":"2008-01-14T21:20:31Z","lastAt":"2008-01-15T07:32:59Z","messageCount":2,"participants":["Martin Koegler","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"65337","messageId":"12003456313661-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"11621","inReplyTo":null,"subject":"[PATCH] parse_commit_buffer: don't parse invalid commits","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2008-01-14T21:20:31Z","receivedAt":"2008-01-14T21:20:31Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\n commit.c |   27 ++++++++++++++++++++-------\n 1 files changed, 20 insertions(+), 7 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex f074811..8b8fb04 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -48,19 +48,32 @@ struct commit *lookup_commit(const unsigned char *sha1)\n \treturn check_commit(obj, sha1, 0);\n }\n \n-static unsigned long parse_commit_date(const char *buf)\n+static unsigned long parse_commit_date(const char *buf, const char *tail)\n {\n \tunsigned long date;\n+\tconst char *dateptr;\n \n+\tif (buf + 6 >= tail)\n+\t\treturn 0;\n \tif (memcmp(buf, \"author\", 6))\n \t\treturn 0;\n-\twhile (*buf++ != '\\n')\n+\twhile (buf < tail && *buf++ != '\\n')\n \t\t/* nada */;\n+\tif (buf + 9 >= tail)\n+\t\treturn 0;\n \tif (memcmp(buf, \"committer\", 9))\n \t\treturn 0;\n-\twhile (*buf++ != '>')\n+\twhile (buf < tail && *buf++ != '>')\n \t\t/* nada */;\n-\tdate = strtoul(buf, NULL, 10);\n+\tif (buf >= tail)\n+\t\treturn 0;\n+\tdateptr = buf;\n+\twhile (buf < tail && *buf++ != '\\n')\n+\t\t/* nada */;\n+\tif (buf >= tail)\n+\t\treturn 0;\n+\t/* dateptr < buf && buf[-1] == '\\n', so strtoul will stop at buf-1 */\n+\tdate = strtoul(dateptr, NULL, 10);\n \tif (date == ULONG_MAX)\n \t\tdate = 0;\n \treturn date;\n@@ -236,9 +249,9 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)\n \t\treturn 0;\n \titem->object.parsed = 1;\n \ttail += size;\n-\tif (tail <= bufptr + 5 || memcmp(bufptr, \"tree \", 5))\n+\tif (tail <= bufptr + 46 || memcmp(bufptr, \"tree \", 5) || bufptr[45] != '\\n')\n \t\treturn error(\"bogus commit object %s\", sha1_to_hex(item->object.sha1));\n-\tif (tail <= bufptr + 45 || get_sha1_hex(bufptr + 5, parent) < 0)\n+\tif (get_sha1_hex(bufptr + 5, parent) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     sha1_to_hex(item->object.sha1));\n \titem->tree = lookup_tree(parent);\n@@ -275,7 +288,7 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)\n \t\t\tn_refs++;\n \t\t}\n \t}\n-\titem->date = parse_commit_date(bufptr);\n+\titem->date = parse_commit_date(bufptr, tail);\n \n \tif (track_object_refs) {\n \t\tunsigned i = 0;\n-- \ngitgui.0.9.1.g61374\n"},{"id":"65365","messageId":"478C61AB.2040103@viscovery.net","threadId":"11621","inReplyTo":"12003456313661-git-send-email-mkoegler@auto.tuwien.ac.at","subject":"Re: [PATCH] parse_commit_buffer: don't parse invalid commits","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-01-15T07:32:59Z","receivedAt":"2008-01-15T07:32:59Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Martin Koegler schrieb:\n> Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n\nQuite a lot has been said about this change and you had a hard time\ndefending it. Why doesn't *anything* of that discussion end up in the\ncommit message? The absolute minimum that belongs there is your definition\nof \"invalid commit\".\n\n-- Hannes\n"}]}