summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-09-24 22:09:35 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-09-24 22:09:35 +0000
commit88d8ee970fb1b7547267fd31912f199dbafd78e1 (patch)
treef426e4174fb9242a858af73b46388ed9db253264
parent6f6a53efbeda1b6b1b8c3a48fc5424f2f428a3fe (diff)
downloadlibapr-88d8ee970fb1b7547267fd31912f199dbafd78e1.tar.gz
* file_io/unix/dir.c (apr_dir_make_recursive): Fix infinite recursion
if mkdir fails for all path components. * test/testdir.c (test_rmkdir_nocwd): Add test case. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@291339 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--file_io/unix/dir.c5
-rw-r--r--test/testdir.c25
2 files changed, 30 insertions, 0 deletions
diff --git a/file_io/unix/dir.c b/file_io/unix/dir.c
index eed7f3a41..849e89d7e 100644
--- a/file_io/unix/dir.c
+++ b/file_io/unix/dir.c
@@ -312,6 +312,11 @@ apr_status_t apr_dir_make_recursive(const char *path, apr_fileperms_t perm,
char *dir;
dir = path_remove_last_component(path, pool);
+ /* If there is no path left, give up. */
+ if (dir[0] == '\0') {
+ return apr_err;
+ }
+
apr_err = apr_dir_make_recursive(dir, perm, pool);
if (!apr_err)
diff --git a/test/testdir.c b/test/testdir.c
index bc2ca9ae6..f59e3e60e 100644
--- a/test/testdir.c
+++ b/test/testdir.c
@@ -219,6 +219,30 @@ static void test_uncleared_errno(abts_case *tc, void *data)
}
+static void test_rmkdir_nocwd(abts_case *tc, void *data)
+{
+ char *cwd, *path;
+
+ APR_ASSERT_SUCCESS(tc, "make temp dir",
+ apr_dir_make("dir3", APR_OS_DEFAULT, p));
+
+ APR_ASSERT_SUCCESS(tc, "obtain cwd", apr_filepath_get(&cwd, 0, p));
+
+ APR_ASSERT_SUCCESS(tc, "determine path to temp dir",
+ apr_filepath_merge(&path, cwd, "dir3", 0, p));
+
+ APR_ASSERT_SUCCESS(tc, "change to temp dir", apr_filepath_set(path, p));
+
+ APR_ASSERT_SUCCESS(tc, "remove temp dir", apr_dir_remove(path, p));
+
+ ABTS_ASSERT(tc, "fail to create dir",
+ apr_dir_make_recursive("foobar", APR_OS_DEFAULT,
+ p) != APR_SUCCESS);
+
+ APR_ASSERT_SUCCESS(tc, "restore cwd", apr_filepath_set(cwd, p));
+}
+
+
abts_suite *testdir(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -230,6 +254,7 @@ abts_suite *testdir(abts_suite *suite)
abts_run_test(suite, test_removeall, NULL);
abts_run_test(suite, test_remove_notthere, NULL);
abts_run_test(suite, test_mkdir_twice, NULL);
+ abts_run_test(suite, test_rmkdir_nocwd, NULL);
abts_run_test(suite, test_rewind, NULL);