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>
Clemens Buchacher committed
May 22, 2010 at 14:21 UTC
4e1f87959c76455f0092a7c82aee78df60533ae5
1 file changed
+2
-4
diff-no-index.c
+2
-4
@@ -150,16 +150,14 @@ static int queue_diff(struct diff_options *o,
150
151
static int path_outside_repo(const char *path)
152
{
153
- /*
154
- * We have already done setup_git_directory_gently() so we
155
- * know we are inside a git work tree already.
156
- */
153
const char *work_tree;
154
size_t len;
155
156
if (!is_absolute_path(path))
157
return 0;
158
work_tree = get_git_work_tree();
159
+ if (!work_tree)
160
+ return 1;
161
len = strlen(work_tree);
162
if (strncmp(path, work_tree, len) ||
163
(path[len] != '\0' && path[len] != '/'))