Skip to content

Commit

Permalink
* file_io/unix/dir.c (apr_dir_make_recursive): Fix infinite recursion
Browse files Browse the repository at this point in the history
if mkdir fails for all path components.

* test/testdir.c (test_rmkdir_nocwd): Add test case.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@291339 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Sep 24, 2005
1 parent 82dc945 commit 24e5e7b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions file_io/unix/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions test/testdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down

0 comments on commit 24e5e7b

Please sign in to comment.