Kernel: Make realpath return silently truncated data

For context, see https://github.com/SerenityOS/serenity/discussions/4357
This commit is contained in:
Ben Wiederhake 2021-01-15 22:29:40 +01:00 committed by Andreas Kling
parent 6f607742dd
commit 68416d7293
Notes: sideshowbarker 2024-07-18 23:10:16 +09:00

View File

@ -49,12 +49,12 @@ int Process::sys$realpath(Userspace<const Syscall::SC_realpath_params*> user_par
auto& custody = custody_or_error.value();
auto absolute_path = custody->absolute_path();
if (absolute_path.length() + 1 > params.buffer.size)
return -ENAMETOOLONG;
if (!copy_to_user(params.buffer.data, absolute_path.characters(), absolute_path.length() + 1))
size_t ideal_size = absolute_path.length() + 1;
auto size_to_copy = min(ideal_size, params.buffer.size);
if (!copy_to_user(params.buffer.data, absolute_path.characters(), size_to_copy))
return -EFAULT;
return 0;
// Note: we return the whole size here, not the copied size.
return ideal_size;
};
}