[haiku-commits] r40819 - haiku/trunk/src/system/kernel/fs

  • From: korli@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 5 Mar 2011 18:17:19 +0100 (CET)

Author: korli
Date: 2011-03-05 18:17:19 +0100 (Sat, 05 Mar 2011)
New Revision: 40819
Changeset: http://dev.haiku-os.org/changeset/40819
Ticket: http://dev.haiku-os.org/ticket/6817

Modified:
   haiku/trunk/src/system/kernel/fs/vfs.cpp
Log:
dir_remove() now handles a path which ends with "/./" and fixed #6817.
Another way would be to disallow removing such a path, as Linux does.


Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp
===================================================================
--- haiku/trunk/src/system/kernel/fs/vfs.cpp    2011-03-05 16:33:57 UTC (rev 
40818)
+++ haiku/trunk/src/system/kernel/fs/vfs.cpp    2011-03-05 17:17:19 UTC (rev 
40819)
@@ -5813,22 +5813,22 @@
        if (path != NULL) {
                // we need to make sure our path name doesn't stop with "/", 
".",
                // or ".."
-               char* lastSlash = strrchr(path, '/');
-               if (lastSlash != NULL) {
+               char* lastSlash;
+               while ((lastSlash = strrchr(path, '/')) != NULL) {
                        char* leaf = lastSlash + 1;
                        if (!strcmp(leaf, ".."))
                                return B_NOT_ALLOWED;
 
                        // omit multiple slashes
-                       while (lastSlash > path && lastSlash[-1] == '/') {
+                       while (lastSlash > path && lastSlash[-1] == '/')
                                lastSlash--;
-                       }
 
-                       if (!leaf[0]
-                               || !strcmp(leaf, ".")) {
-                               // "name/" -> "name", or "name/." -> "name"
-                               lastSlash[0] = '\0';
+                       if (leaf[0]
+                               && strcmp(leaf, ".")) {
+                               break;
                        }
+                       // "name/" -> "name", or "name/." -> "name"
+                       lastSlash[0] = '\0';
                }
 
                if (!strcmp(path, ".") || !strcmp(path, ".."))


Other related posts:

  • » [haiku-commits] r40819 - haiku/trunk/src/system/kernel/fs - korli