Skip to content

Commit 4e1f879

Browse files
Clemens Buchachergitster
authored andcommitted
test get_git_work_tree() return value for NULL
If we are in a git directory, get_git_work_tree() can return NULL. While trying to determine whether or not the given paths are outside the work tree, the following command would read from it anyways and trigger a segmentation fault. git diff / / Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c8b2964 commit 4e1f879

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

diff-no-index.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,14 @@ static int queue_diff(struct diff_options *o,
150150

151151
static int path_outside_repo(const char *path)
152152
{
153-
/*
154-
* We have already done setup_git_directory_gently() so we
155-
* know we are inside a git work tree already.
156-
*/
157153
const char *work_tree;
158154
size_t len;
159155

160156
if (!is_absolute_path(path))
161157
return 0;
162158
work_tree = get_git_work_tree();
159+
if (!work_tree)
160+
return 1;
163161
len = strlen(work_tree);
164162
if (strncmp(path, work_tree, len) ||
165163
(path[len] != '\0' && path[len] != '/'))

0 commit comments

Comments
 (0)