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
This commit is contained in:
@@ -5813,22 +5813,22 @@ dir_remove(int fd, char* path, bool kernel)
|
|||||||
if (path != NULL) {
|
if (path != NULL) {
|
||||||
// we need to make sure our path name doesn't stop with "/", ".",
|
// we need to make sure our path name doesn't stop with "/", ".",
|
||||||
// or ".."
|
// or ".."
|
||||||
char* lastSlash = strrchr(path, '/');
|
char* lastSlash;
|
||||||
if (lastSlash != NULL) {
|
while ((lastSlash = strrchr(path, '/')) != NULL) {
|
||||||
char* leaf = lastSlash + 1;
|
char* leaf = lastSlash + 1;
|
||||||
if (!strcmp(leaf, ".."))
|
if (!strcmp(leaf, ".."))
|
||||||
return B_NOT_ALLOWED;
|
return B_NOT_ALLOWED;
|
||||||
|
|
||||||
// omit multiple slashes
|
// omit multiple slashes
|
||||||
while (lastSlash > path && lastSlash[-1] == '/') {
|
while (lastSlash > path && lastSlash[-1] == '/')
|
||||||
lastSlash--;
|
lastSlash--;
|
||||||
}
|
|
||||||
|
|
||||||
if (!leaf[0]
|
if (leaf[0]
|
||||||
|| !strcmp(leaf, ".")) {
|
&& strcmp(leaf, ".")) {
|
||||||
// "name/" -> "name", or "name/." -> "name"
|
break;
|
||||||
lastSlash[0] = '\0';
|
|
||||||
}
|
}
|
||||||
|
// "name/" -> "name", or "name/." -> "name"
|
||||||
|
lastSlash[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(path, ".") || !strcmp(path, ".."))
|
if (!strcmp(path, ".") || !strcmp(path, ".."))
|
||||||
|
|||||||
Reference in New Issue
Block a user