summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-01-15 22:29:40 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-16 22:40:53 +0100
commit68416d72935de7554cd034977b1f7b378126d4c4 (patch)
treed20d4aba75f61bc96bad5fac5210f2b03c8f294e /Kernel
parent6f607742dd50184c2fe52008b820ffeea810effd (diff)
downloadserenity-68416d72935de7554cd034977b1f7b378126d4c4.zip
Kernel: Make realpath return silently truncated data
For context, see https://github.com/SerenityOS/serenity/discussions/4357
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Syscalls/realpath.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/Kernel/Syscalls/realpath.cpp b/Kernel/Syscalls/realpath.cpp
index 83f6cba839..93a3dea706 100644
--- a/Kernel/Syscalls/realpath.cpp
+++ b/Kernel/Syscalls/realpath.cpp
@@ -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;
};
}