Skip to content

Commit a0601dc

Browse files
mhaggergitster
authored andcommitted
absolute_path(): reject the empty string
Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17264bc commit a0601dc

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

abspath.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ const char *absolute_path(const char *path)
123123
{
124124
static char buf[PATH_MAX + 1];
125125

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)) {
127129
if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
128130
die("Too long path: %.*s", 60, path);
129131
} else {

t/t0060-path-utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ test_expect_success 'strip_path_suffix' '
140140
c:/msysgit/libexec//git-core libexec/git-core)
141141
'
142142

143-
test_expect_failure 'absolute path rejects the empty string' '
143+
test_expect_success 'absolute path rejects the empty string' '
144144
test_must_fail test-path-utils absolute_path ""
145145
'
146146

0 commit comments

Comments
 (0)