mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:07:34 +00:00
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.
This commit is contained in:
parent
dd1996ca68
commit
00e56cda0c
1 changed files with 8 additions and 0 deletions
|
@ -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, ...)
|
int open(const char* path, int options, ...)
|
||||||
{
|
{
|
||||||
|
if (!path) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, options);
|
va_start(ap, options);
|
||||||
auto mode = (mode_t)va_arg(ap, unsigned);
|
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, ...)
|
int openat(int dirfd, const char* path, int options, ...)
|
||||||
{
|
{
|
||||||
|
if (!path) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, options);
|
va_start(ap, options);
|
||||||
auto mode = (mode_t)va_arg(ap, unsigned);
|
auto mode = (mode_t)va_arg(ap, unsigned);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue