diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | file_io/unix/dir.c | 5 | ||||
-rw-r--r-- | test/testdir.c | 24 |
3 files changed, 32 insertions, 0 deletions
@@ -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); |