mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
UserlandEmulator: Fix data loss in realpath/readlink
This 'data loss' was introduced in 809a8ee693
, because
I hoped we could eventually outlaw overlong paths entirely. This sparked some discussion:
https://github.com/SerenityOS/serenity/discussions/4357
Among other things, we agree that yeah, the Kernel can and should be able to return
paths of arbitrary length. This means that the 'arbitrary' maximum of PATH_MAX in
UserspaceEmulator should be considered to be unnecessary data loss, and as such, needs to
be fixed.
This commit is contained in:
parent
5dc29065e1
commit
7ed002d1ca
Notes:
sideshowbarker
2024-07-18 23:10:07 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/7ed002d1ca5 Pull-request: https://github.com/SerenityOS/serenity/pull/4965 Reviewed-by: https://github.com/bugaevc Reviewed-by: https://github.com/emanuele6
@ -1364,20 +1364,16 @@ int Emulator::virt$realpath(FlatPtr params_addr)
|
||||
Syscall::SC_realpath_params params;
|
||||
mmu().copy_from_vm(¶ms, params_addr, sizeof(params));
|
||||
|
||||
if (params.path.length > PATH_MAX) {
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
auto path = mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length);
|
||||
char host_buffer[PATH_MAX] = {};
|
||||
size_t host_buffer_size = min(sizeof(host_buffer), params.buffer.size);
|
||||
auto host_buffer = ByteBuffer::create_zeroed(params.buffer.size);
|
||||
|
||||
Syscall::SC_realpath_params host_params;
|
||||
host_params.path = { (const char*)path.data(), path.size() };
|
||||
host_params.buffer = { host_buffer, host_buffer_size };
|
||||
host_params.buffer = { (char*)host_buffer.data(), host_buffer.size() };
|
||||
int rc = syscall(SC_realpath, &host_params);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
mmu().copy_to_vm((FlatPtr)params.buffer.data, host_buffer, host_buffer_size);
|
||||
mmu().copy_to_vm((FlatPtr)params.buffer.data, host_buffer.data(), host_buffer.size());
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1759,20 +1755,16 @@ int Emulator::virt$readlink(FlatPtr params_addr)
|
||||
Syscall::SC_readlink_params params;
|
||||
mmu().copy_from_vm(¶ms, params_addr, sizeof(params));
|
||||
|
||||
if (params.path.length > PATH_MAX) {
|
||||
return -ENAMETOOLONG;
|
||||
}
|
||||
auto path = mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length);
|
||||
char host_buffer[PATH_MAX] = {};
|
||||
size_t host_buffer_size = min(sizeof(host_buffer), params.buffer.size);
|
||||
auto host_buffer = ByteBuffer::create_zeroed(params.buffer.size);
|
||||
|
||||
Syscall::SC_readlink_params host_params;
|
||||
host_params.path = { (const char*)path.data(), path.size() };
|
||||
host_params.buffer = { host_buffer, host_buffer_size };
|
||||
host_params.buffer = { (char*)host_buffer.data(), host_buffer.size() };
|
||||
int rc = syscall(SC_readlink, &host_params);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
mmu().copy_to_vm((FlatPtr)params.buffer.data, host_buffer, host_buffer_size);
|
||||
mmu().copy_to_vm((FlatPtr)params.buffer.data, host_buffer.data(), host_buffer.size());
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user