summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-09-24 22:27:18 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2005-09-24 22:27:18 +0000
commit825484e638ce04c343c7f7d5f96fe109f03f51f9 (patch)
tree2e183b6c56e811ffae881455333750e82ade1990
parentcc7e151cd517e31f5ee1af0820ab182f7ff356ae (diff)
downloadlibapr-825484e638ce04c343c7f7d5f96fe109f03f51f9.tar.gz
Merge r291339 from trunk:
* 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/branches/0.9.x@291341 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--CHANGES3
-rw-r--r--file_io/unix/dir.c5
-rw-r--r--test/testdir.c24
3 files changed, 32 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 6c8bd0b34..194b26f37 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
Changes with APR 0.9.7
+ *) Fix crash in apr_dir_make_recursive() for relative path
+ when the working directory has been deleted. [Joe Orton]
+
*) Win32: fix apr_proc_mutex_trylock() to handle WAIT_TIMEOUT,
returning APR_EBUSY. [Ronen Mizrahi <ronen@tversity.com>]
diff --git a/file_io/unix/dir.c b/file_io/unix/dir.c
index 86bd43761..d6f69a4c7 100644
--- a/file_io/unix/dir.c
+++ b/file_io/unix/dir.c
@@ -276,6 +276,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 1e2227473..e1b08425e 100644
--- a/test/testdir.c
+++ b/test/testdir.c
@@ -219,6 +219,29 @@ static void test_uncleared_errno(CuTest *tc)
}
+static void test_rmkdir_nocwd(CuTest *tc)
+{
+ 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));
+
+ CuAssert(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));
+}
+
CuSuite *testdir(void)
{
CuSuite *suite = CuSuiteNew("Directory");
@@ -230,6 +253,7 @@ CuSuite *testdir(void)
SUITE_ADD_TEST(suite, test_removeall);
SUITE_ADD_TEST(suite, test_remove_notthere);
SUITE_ADD_TEST(suite, test_mkdir_twice);
+ SUITE_ADD_TEST(suite, test_rmkdir_nocwd);
SUITE_ADD_TEST(suite, test_rewind);