absolute_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:40 UTC a0601dc11fab5b4525a348b2ad6c9bb92529a281
2 files changed +4 -2
abspath.c
+3 -1
@@ -123,7 +123,9 @@ const char *absolute_path(const char *path)
123 {
124 static char buf[PATH_MAX + 1];
125
126 - if (is_absolute_path(path)) {
126 + if (!*path) {
127 + die("The empty string is not a valid path");
128 + } else if (is_absolute_path(path)) {
129 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
130 die("Too long path: %.*s", 60, path);
131 } else {
t/t0060-path-utils.sh
+1 -1
@@ -140,7 +140,7 @@ test_expect_success 'strip_path_suffix' '
140 c:/msysgit/libexec//git-core libexec/git-core)
141 '
142
143 -test_expect_failure 'absolute path rejects the empty string' '
143 +test_expect_success 'absolute path rejects the empty string' '
144 test_must_fail test-path-utils absolute_path ""
145 '
146