From 3efe5d1d32fde899b23ebbb1fde499a0897e1c4e Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:01 +0200 Subject: [PATCH] real_path(): reject the empty string Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- abspath.c | 3 +++ t/t0060-path-utils.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/abspath.c b/abspath.c index 5d624307d5..3e8325c736 100644 --- a/abspath.c +++ b/abspath.c @@ -35,6 +35,9 @@ const char *real_path(const char *path) if (path == buf || path == next_buf) return path; + if (!*path) + die("The empty string is not a valid path"); + if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX) die ("Too long path: %.*s", 60, path); diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 1118056a1f..fab5ea28b2 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -144,7 +144,7 @@ test_expect_success 'absolute path rejects the empty string' ' test_must_fail test-path-utils absolute_path "" ' -test_expect_failure 'real path rejects the empty string' ' +test_expect_success 'real path rejects the empty string' ' test_must_fail test-path-utils real_path "" ' -- 2.11.4.GIT