real_path(): reject the empty string

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Sep 7, 2012 at 00:41 UTC 3efe5d1d32fde899b23ebbb1fde499a0897e1c4e
2 files changed +4 -1
abspath.c
+3
@@ -35,6 +35,9 @@ const char *real_path(const char *path)
35 if (path == buf || path == next_buf)
36 return path;
37
38 + if (!*path)
39 + die("The empty string is not a valid path");
40 +
41 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
42 die ("Too long path: %.*s", 60, path);
43
t/t0060-path-utils.sh
+1 -1
@@ -144,7 +144,7 @@ test_expect_success 'absolute path rejects the empty string' '
144 test_must_fail test-path-utils absolute_path ""
145 '
146
147 -test_expect_failure 'real path rejects the empty string' '
147 +test_expect_success 'real path rejects the empty string' '
148 test_must_fail test-path-utils real_path ""
149 '
150