Compare commits

..

No commits in common. "3b4214c8be1c39510f6350727a2819e116dacf34" and "82e7b0e860b80d60ff6829ba583f172a2ba1b1e5" have entirely different histories.

4 changed files with 0 additions and 42 deletions

View File

@ -3,7 +3,6 @@
#include "thread/Thread.h" #include "thread/Thread.h"
#include <bits/modes.h> #include <bits/modes.h>
#include <luna/PathParser.h> #include <luna/PathParser.h>
#include <luna/Utf8.h>
namespace VFS namespace VFS
{ {
@ -47,8 +46,6 @@ namespace VFS
auto child_name = TRY(parser.basename()); auto child_name = TRY(parser.basename());
TRY(validate_filename(child_name.view()));
return parent_inode->create_subdirectory(child_name.chars()); return parent_inode->create_subdirectory(child_name.chars());
} }
@ -63,41 +60,9 @@ namespace VFS
auto child_name = TRY(parser.basename()); auto child_name = TRY(parser.basename());
TRY(validate_filename(child_name.view()));
return parent_inode->create_file(child_name.chars()); return parent_inode->create_file(child_name.chars());
} }
Result<void> validate_filename(StringView name)
{
// Forbid problematic characters that could cause trouble in shell scripts and the like.
if (strpbrk(name.chars(), "*?:[]\"<>\\")) return err(EINVAL);
// Forbid filenames starting with a hyphen.
if (!name.is_empty() && name[0] == '-') return err(EINVAL);
// Forbid filenames with leading spaces.
if (!name.is_empty() && name[0] == ' ') return err(EINVAL);
// Forbid filenames with trailing spaces.
if (!name.is_empty() && name[name.length() - 1] == ' ') return err(EINVAL);
for (const auto& c : name)
{
// Forbid filenames with control characters.
if (c < 32 || c == 127) return err(EINVAL);
}
// Forbid filenames that are not valid UTF-8.
Utf8StringDecoder decoder(name.chars());
// This will fail if the filename is invalid UTF-8.
TRY(decoder.code_points());
return {};
}
bool can_execute(SharedPtr<Inode> inode, Credentials auth) bool can_execute(SharedPtr<Inode> inode, Credentials auth)
{ {
if (inode->uid() == auth.euid) { return inode->mode() & S_IXUSR; } if (inode->uid() == auth.euid) { return inode->mode() & S_IXUSR; }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <luna/SharedPtr.h> #include <luna/SharedPtr.h>
#include <luna/StaticString.h> #include <luna/StaticString.h>
#include <luna/StringView.h>
#include <sys/types.h> #include <sys/types.h>
struct Credentials; struct Credentials;
@ -212,8 +211,6 @@ namespace VFS
Result<SharedPtr<Inode>> create_file(const char* path, Credentials auth, Result<SharedPtr<Inode>> create_file(const char* path, Credentials auth,
SharedPtr<VFS::Inode> working_directory = {}); SharedPtr<VFS::Inode> working_directory = {});
Result<void> validate_filename(StringView name);
bool can_execute(SharedPtr<Inode> inode, Credentials auth); bool can_execute(SharedPtr<Inode> inode, Credentials auth);
bool can_read(SharedPtr<Inode> inode, Credentials auth); bool can_read(SharedPtr<Inode> inode, Credentials auth);
bool can_write(SharedPtr<Inode> inode, Credentials auth); bool can_write(SharedPtr<Inode> inode, Credentials auth);

View File

@ -22,8 +22,6 @@ Result<u64> sys_mknod(Registers*, SyscallArgs args)
auto dirname = TRY(parser.dirname()); auto dirname = TRY(parser.dirname());
auto basename = TRY(parser.basename()); auto basename = TRY(parser.basename());
TRY(VFS::validate_filename(basename.view()));
auto parent = TRY(VFS::resolve_path(dirname.chars(), current->auth, current->current_directory)); auto parent = TRY(VFS::resolve_path(dirname.chars(), current->auth, current->current_directory));
if (!VFS::can_write(parent, current->auth)) return err(EACCES); if (!VFS::can_write(parent, current->auth)) return err(EACCES);

View File

@ -32,8 +32,6 @@ extern "C"
usize len = strlen(path); usize len = strlen(path);
if (!len) return dot; if (!len) return dot;
if (len == 1 && *path != '/') return dot;
// Strip trailing slashes. // Strip trailing slashes.
char* it = path + len - 1; char* it = path + len - 1;
while (*it == '/' && it != path) { it--; } while (*it == '/' && it != path) { it--; }