Skip to content

Commit 1688ea5

Browse files
committed
[Kernel] Replaced TranslateAnsiString with TranslateAnsiPath for file paths.
This removes paths that starts or ends with whitespace characters
1 parent e80d4ef commit 1688ea5

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

src/xenia/kernel/util/shim_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ inline std::string_view TranslateAnsiString(const Memory* memory,
9393
ansi_string->length);
9494
}
9595

96+
inline std::string TranslateAnsiPath(const Memory* memory,
97+
const X_ANSI_STRING* ansi_string) {
98+
return string_util::trim(
99+
std::string(TranslateAnsiString(memory, ansi_string)));
100+
}
101+
96102
inline std::string_view TranslateAnsiStringAddress(const Memory* memory,
97103
uint32_t guest_address) {
98104
if (!guest_address) {

src/xenia/kernel/xboxkrnl/xboxkrnl_io.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dword_result_t NtCreateFile_entry(lpdword_t handle_out, dword_t desired_access,
6363
vfs::Entry* root_entry = nullptr;
6464

6565
// Compute path, possibly attrs relative.
66-
auto target_path = util::TranslateAnsiString(kernel_memory(), object_name);
66+
auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name);
6767

6868
// Enforce that the path is ASCII.
6969
if (!IsValidPath(target_path, false)) {
@@ -462,7 +462,7 @@ dword_result_t NtQueryFullAttributesFile_entry(
462462
assert_always();
463463
}
464464

465-
auto target_path = util::TranslateAnsiString(kernel_memory(), object_name);
465+
auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name);
466466

467467
// Enforce that the path is ASCII.
468468
if (!IsValidPath(target_path, false)) {
@@ -501,7 +501,7 @@ dword_result_t NtQueryDirectoryFile_entry(
501501
uint32_t info = 0;
502502

503503
auto file = kernel_state()->object_table()->LookupObject<XFile>(file_handle);
504-
auto name = util::TranslateAnsiString(kernel_memory(), file_name);
504+
auto name = util::TranslateAnsiPath(kernel_memory(), file_name);
505505

506506
// Enforce that the path is ASCII.
507507
if (!IsValidPath(name, true)) {
@@ -558,7 +558,7 @@ dword_result_t NtOpenSymbolicLinkObject_entry(
558558
auto object_name =
559559
kernel_memory()->TranslateVirtual<X_ANSI_STRING*>(object_attrs->name_ptr);
560560

561-
auto target_path = util::TranslateAnsiString(kernel_memory(), object_name);
561+
auto target_path = util::TranslateAnsiPath(kernel_memory(), object_name);
562562

563563
// Enforce that the path is ASCII.
564564
if (!IsValidPath(target_path, false)) {

src/xenia/kernel/xboxkrnl/xboxkrnl_io_info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ dword_result_t NtSetInformationFile_entry(
234234
auto info = info_ptr.as<X_FILE_RENAME_INFORMATION*>();
235235
// Compute path, possibly attrs relative.
236236
std::filesystem::path target_path =
237-
util::TranslateAnsiString(kernel_memory(), &info->ansi_string);
237+
util::TranslateAnsiPath(kernel_memory(), &info->ansi_string);
238238

239239
// Place IsValidPath in path from where it can be accessed everywhere
240240
if (!IsValidPath(target_path.string(), false)) {

src/xenia/kernel/xboxkrnl/xboxkrnl_modules.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ dword_result_t XexLoadImageHeaders_entry(pointer_t<X_ANSI_STRING> path,
263263
return X_STATUS_BUFFER_TOO_SMALL;
264264
}
265265
auto current_kernel = ctx->kernel_state;
266-
auto target_path = util::TranslateAnsiString(current_kernel->memory(), path);
266+
auto target_path = util::TranslateAnsiPath(current_kernel->memory(), path);
267267

268268
vfs::File* vfs_file = nullptr;
269269
vfs::FileAction file_action;

src/xenia/kernel/xboxkrnl/xboxkrnl_ob.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ DECLARE_XBOXKRNL_EXPORT1(ObReferenceObject, kNone, kImplemented);
350350
dword_result_t ObCreateSymbolicLink_entry(pointer_t<X_ANSI_STRING> path_ptr,
351351
pointer_t<X_ANSI_STRING> target_ptr) {
352352
auto path = xe::utf8::canonicalize_guest_path(
353-
util::TranslateAnsiString(kernel_memory(), path_ptr));
353+
util::TranslateAnsiPath(kernel_memory(), path_ptr));
354354
auto target = xe::utf8::canonicalize_guest_path(
355-
util::TranslateAnsiString(kernel_memory(), target_ptr));
355+
util::TranslateAnsiPath(kernel_memory(), target_ptr));
356356

357357
if (xe::utf8::starts_with(path, "\\??\\")) {
358358
path = path.substr(4); // Strip the full qualifier
@@ -367,7 +367,7 @@ dword_result_t ObCreateSymbolicLink_entry(pointer_t<X_ANSI_STRING> path_ptr,
367367
DECLARE_XBOXKRNL_EXPORT1(ObCreateSymbolicLink, kNone, kImplemented);
368368

369369
dword_result_t ObDeleteSymbolicLink_entry(pointer_t<X_ANSI_STRING> path_ptr) {
370-
auto path = util::TranslateAnsiString(kernel_memory(), path_ptr);
370+
auto path = util::TranslateAnsiPath(kernel_memory(), path_ptr);
371371
if (!kernel_state()->file_system()->UnregisterSymbolicLink(path)) {
372372
return X_STATUS_UNSUCCESSFUL;
373373
}

0 commit comments

Comments
 (0)