Skip to content

Commit

Permalink
test get_git_work_tree() return value for NULL
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Clemens Buchacher authored and gitster committed May 25, 2010
1 parent c8b2964 commit 4e1f879
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions diff-no-index.c
Expand Up @@ -150,16 +150,14 @@ static int queue_diff(struct diff_options *o,

static int path_outside_repo(const char *path)
{
/*
* We have already done setup_git_directory_gently() so we
* know we are inside a git work tree already.
*/
const char *work_tree;
size_t len;

if (!is_absolute_path(path))
return 0;
work_tree = get_git_work_tree();
if (!work_tree)
return 1;
len = strlen(work_tree);
if (strncmp(path, work_tree, len) ||
(path[len] != '\0' && path[len] != '/'))
Expand Down

0 comments on commit 4e1f879

Please sign in to comment.