You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2005/09/25 00:22:07 UTC

svn commit: r291340 - in /apr/apr/branches/1.2.x: CHANGES file_io/unix/dir.c test/testdir.c

Author: jorton
Date: Sat Sep 24 15:22:00 2005
New Revision: 291340

URL: http://svn.apache.org/viewcvs?rev=291340&view=rev
Log:
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.

Modified:
    apr/apr/branches/1.2.x/CHANGES
    apr/apr/branches/1.2.x/file_io/unix/dir.c
    apr/apr/branches/1.2.x/test/testdir.c

Modified: apr/apr/branches/1.2.x/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/branches/1.2.x/CHANGES?rev=291340&r1=291339&r2=291340&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/CHANGES (original)
+++ apr/apr/branches/1.2.x/CHANGES Sat Sep 24 15:22:00 2005
@@ -1,5 +1,8 @@
 Changes for APR 1.2.2
 
+  *) 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 <ro...@tversity.com>]
 

Modified: apr/apr/branches/1.2.x/file_io/unix/dir.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/1.2.x/file_io/unix/dir.c?rev=291340&r1=291339&r2=291340&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/file_io/unix/dir.c (original)
+++ apr/apr/branches/1.2.x/file_io/unix/dir.c Sat Sep 24 15:22:00 2005
@@ -276,6 +276,11 @@
         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) 

Modified: apr/apr/branches/1.2.x/test/testdir.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/1.2.x/test/testdir.c?rev=291340&r1=291339&r2=291340&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/test/testdir.c (original)
+++ apr/apr/branches/1.2.x/test/testdir.c Sat Sep 24 15:22:00 2005
@@ -219,6 +219,30 @@
 
 }
 
+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_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);