From 8775d8d25d66d46c31d929547b6f16b9a88900a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 5 Mar 2011 17:17:19 +0000 Subject: [PATCH] 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40819 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/fs/vfs.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index b189db68b4..85be4e8c5a 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -5813,22 +5813,22 @@ dir_remove(int fd, char* path, bool kernel) 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, ".."))