summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2020-01-06 10:51:50 +0100
committerAndreas Kling <awesomekling@gmail.com>2020-01-06 11:15:49 +0100
commit53d3b6b0a70802bad58ef6c2ec034aa4e8ebf3e6 (patch)
tree57c07938e5c7d03cc267f1934a706c60308f7340 /Libraries
parent642137f014ad9b9bdc92fc9b2e928d1ea62462ba (diff)
downloadserenity-53d3b6b0a70802bad58ef6c2ec034aa4e8ebf3e6.zip
LibC: Make the syscall wrappers for stat/lstat/chdir return EFAULT
If we pass a null path to these syscall wrappers, just return EFAULT directly from the wrapper instead of segfaulting by calling strlen(). This is a compromise, since we now have to pass the path length to the kernel, so we can't rely on the kernel to tell us that the path is at a bad memory address.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/unistd.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp
index 8c0f093f3f..70cd0f7e8e 100644
--- a/Libraries/LibC/unistd.cpp
+++ b/Libraries/LibC/unistd.cpp
@@ -227,12 +227,20 @@ pid_t waitpid(pid_t waitee, int* wstatus, int options)
int lstat(const char* path, struct stat* statbuf)
{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
int rc = syscall(SC_lstat, path, strlen(path), statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int stat(const char* path, struct stat* statbuf)
{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
int rc = syscall(SC_stat, path, strlen(path), statbuf);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
@@ -245,6 +253,10 @@ int fstat(int fd, struct stat* statbuf)
int chdir(const char* path)
{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
int rc = syscall(SC_chdir, path, strlen(path));
__RETURN_WITH_ERRNO(rc, rc, -1);
}