summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Mayer <till.mayer@web.de>2019-11-13 20:21:46 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-14 08:32:03 +0100
commit00e56cda0c2e302d62f87f45e7cb24323cfa92d7 (patch)
tree4db852fe50c02e60e21a051894fa92989ef86bff
parentdd1996ca68a493e8140ca2ab3e22bef670c25c28 (diff)
downloadserenity-00e56cda0c2e302d62f87f45e7cb24323cfa92d7.zip
LibC: open/openat: Make sure path is not a nullptr before dereferencing
open and openat both try to get the length of the path string. When the path was a nullptr, strlen tried to dereference it, causing a segfault.
-rw-r--r--Libraries/LibC/unistd.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp
index 2e19149d8f..c935b27769 100644
--- a/Libraries/LibC/unistd.cpp
+++ b/Libraries/LibC/unistd.cpp
@@ -202,6 +202,10 @@ int openat_with_path_length(int dirfd, const char* path, size_t path_length, int
int open(const char* path, int options, ...)
{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
va_list ap;
va_start(ap, options);
auto mode = (mode_t)va_arg(ap, unsigned);
@@ -211,6 +215,10 @@ int open(const char* path, int options, ...)
int openat(int dirfd, const char* path, int options, ...)
{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
va_list ap;
va_start(ap, options);
auto mode = (mode_t)va_arg(ap, unsigned);