{"thread":{"id":"23876","subject":"[PATCH] test get_git_work_tree() return value for NULL","startedAt":"2010-05-22T12:21:27Z","lastAt":"2010-05-26T05:07:18Z","messageCount":2,"participants":["Clemens Buchacher","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"142096","messageId":"20100522122127.GA13372@localhost","threadId":"23876","inReplyTo":null,"subject":"[PATCH] test get_git_work_tree() return value for NULL","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2010-05-22T12:21:27Z","receivedAt":"2010-05-22T12:21:27Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"If we are in a git directory, get_git_work_tree() can return NULL.\nWhile trying to determine whether or not the given paths are outside\nthe work tree, the following command would read from it anyways and\ntrigger a segmentation fault.\n\n git diff / /\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n diff-no-index.c |    6 ++----\n 1 files changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/diff-no-index.c b/diff-no-index.c\nindex aae8e7a..4cd9dac 100644\n--- a/diff-no-index.c\n+++ b/diff-no-index.c\n@@ -150,16 +150,14 @@ static int queue_diff(struct diff_options *o,\n \n static int path_outside_repo(const char *path)\n {\n-\t/*\n-\t * We have already done setup_git_directory_gently() so we\n-\t * know we are inside a git work tree already.\n-\t */\n \tconst char *work_tree;\n \tsize_t len;\n \n \tif (!is_absolute_path(path))\n \t\treturn 0;\n \twork_tree = get_git_work_tree();\n+\tif (!work_tree)\n+\t\treturn 1;\n \tlen = strlen(work_tree);\n \tif (strncmp(path, work_tree, len) ||\n \t    (path[len] != '\\0' && path[len] != '/'))\n-- \n1.7.0.5.3.ga76e\n"},{"id":"142307","messageId":"7vocg3qmih.fsf@alter.siamese.dyndns.org","threadId":"23876","inReplyTo":"20100522122127.GA13372@localhost","subject":"Re: [PATCH] test get_git_work_tree() return value for NULL","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-05-26T05:07:18Z","receivedAt":"2010-05-26T05:07:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}