lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r930398 - in /lucene/lucy/trunk/core/Lucy: Store/Folder.c Test/Store/TestFSFolder.c
Date Fri, 02 Apr 2010 21:45:46 GMT
Author: marvin
Date: Fri Apr  2 21:45:46 2010
New Revision: 930398

URL: http://svn.apache.org/viewvc?rev=930398&view=rev
Log:
Verify that List_R() won't follow symlinks.  This is important because we'll
use List_R() to create lists of files to delete when recycling segments and we
don't want a maliciously placed symlink triggering recursive deletion of a
directory tree outside the index folder.

Modified:
    lucene/lucy/trunk/core/Lucy/Store/Folder.c
    lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c

Modified: lucene/lucy/trunk/core/Lucy/Store/Folder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Store/Folder.c?rev=930398&r1=930397&r2=930398&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Store/Folder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Store/Folder.c Fri Apr  2 21:45:46 2010
@@ -223,7 +223,7 @@ S_add_to_file_list(Folder *self, VArray 
             }
             VA_Push(list, (Obj*)relpath);
 
-            if (DH_Entry_Is_Dir(dh)) {
+            if (DH_Entry_Is_Dir(dh) && !DH_Entry_Is_Symlink(dh)) {
                 CharBuf *subdir = CB_Get_Size(dir) 
                                 ? CB_newf("%o/%o", dir, entry)
                                 : CB_Clone(entry);

Modified: lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c?rev=930398&r1=930397&r2=930398&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Store/TestFSFolder.c Fri Apr  2 21:45:46 2010
@@ -74,13 +74,27 @@ test_protect_symlinks(TestBatch *batch) 
     OutStream *outstream = FSFolder_Open_Out(folder, foo_boffo);
     DECREF(outstream);
 
-    if (symlink("_fstest/foo/boffo", "_fstest/bar/banana")) {
+    if (   symlink("_fstest/foo/boffo", "_fstest/bar/banana")
+        || symlink("_fstest/foo", "_fstest/bar/bazooka")
+    ) {
+        FAIL(batch, "symlink() failed");
         FAIL(batch, "symlink() failed");
         FAIL(batch, "symlink() failed");
         FAIL(batch, "symlink() failed");
         FAIL(batch, "symlink() failed");
     }
     else {
+        VArray *list = FSFolder_List_R(folder);
+        bool_t saw_bazooka_boffo = false;
+        for (uint32_t i = 0, max = VA_Get_Size(list); i < max; i++) {
+            CharBuf *entry = (CharBuf*)VA_Fetch(list, i);
+            if (CB_Ends_With_Str(entry, "bazooka/boffo", 13)) {
+                saw_bazooka_boffo = true;
+            }
+        }
+        ASSERT_FALSE(batch, saw_bazooka_boffo, 
+            "List_R() shouldn't follow symlinks");
+
         ASSERT_TRUE(batch, FSFolder_Delete_Tree(folder, bar), 
             "Delete_Tree() returns true"), 
         ASSERT_FALSE(batch, FSFolder_Exists(folder, bar), 
@@ -99,6 +113,7 @@ test_protect_symlinks(TestBatch *batch) 
     SKIP(batch, "No symlink() function");
     SKIP(batch, "No symlink() function");
     SKIP(batch, "No symlink() function");
+    SKIP(batch, "No symlink() function");
 #endif /* CHY_HAS_UNISTD_H */
 }
 
@@ -128,7 +143,7 @@ test_disallow_updir(TestBatch *batch)
 void
 TestFSFolder_run_tests()
 {
-    u32_t num_tests = TestFolderCommon_num_tests() + 8;
+    u32_t num_tests = TestFolderCommon_num_tests() + 9;
     TestBatch *batch = TestBatch_new(num_tests);
 
     TestBatch_Plan(batch);



Mime
View raw message