Compare commits
No commits in common. "3b4214c8be1c39510f6350727a2819e116dacf34" and "82e7b0e860b80d60ff6829ba583f172a2ba1b1e5" have entirely different histories.
3b4214c8be
...
82e7b0e860
@ -3,7 +3,6 @@
|
||||
#include "thread/Thread.h"
|
||||
#include <bits/modes.h>
|
||||
#include <luna/PathParser.h>
|
||||
#include <luna/Utf8.h>
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
@ -47,8 +46,6 @@ namespace VFS
|
||||
|
||||
auto child_name = TRY(parser.basename());
|
||||
|
||||
TRY(validate_filename(child_name.view()));
|
||||
|
||||
return parent_inode->create_subdirectory(child_name.chars());
|
||||
}
|
||||
|
||||
@ -63,41 +60,9 @@ namespace VFS
|
||||
|
||||
auto child_name = TRY(parser.basename());
|
||||
|
||||
TRY(validate_filename(child_name.view()));
|
||||
|
||||
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)
|
||||
{
|
||||
if (inode->uid() == auth.euid) { return inode->mode() & S_IXUSR; }
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include <luna/SharedPtr.h>
|
||||
#include <luna/StaticString.h>
|
||||
#include <luna/StringView.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct Credentials;
|
||||
@ -212,8 +211,6 @@ namespace VFS
|
||||
Result<SharedPtr<Inode>> create_file(const char* path, Credentials auth,
|
||||
SharedPtr<VFS::Inode> working_directory = {});
|
||||
|
||||
Result<void> validate_filename(StringView name);
|
||||
|
||||
bool can_execute(SharedPtr<Inode> inode, Credentials auth);
|
||||
bool can_read(SharedPtr<Inode> inode, Credentials auth);
|
||||
bool can_write(SharedPtr<Inode> inode, Credentials auth);
|
||||
|
@ -22,8 +22,6 @@ Result<u64> sys_mknod(Registers*, SyscallArgs args)
|
||||
auto dirname = TRY(parser.dirname());
|
||||
auto basename = TRY(parser.basename());
|
||||
|
||||
TRY(VFS::validate_filename(basename.view()));
|
||||
|
||||
auto parent = TRY(VFS::resolve_path(dirname.chars(), current->auth, current->current_directory));
|
||||
if (!VFS::can_write(parent, current->auth)) return err(EACCES);
|
||||
|
||||
|
@ -32,8 +32,6 @@ extern "C"
|
||||
usize len = strlen(path);
|
||||
if (!len) return dot;
|
||||
|
||||
if (len == 1 && *path != '/') return dot;
|
||||
|
||||
// Strip trailing slashes.
|
||||
char* it = path + len - 1;
|
||||
while (*it == '/' && it != path) { it--; }
|
||||
|
Loading…
Reference in New Issue
Block a user