From f1bb7b29c429f8f96c38de3068b3eafbe82c4076 Mon Sep 17 00:00:00 2001 From: Steffen Schulz Date: Fri, 4 Nov 2022 16:29:41 -0700 Subject: [PATCH] check for successful chdir() --- nyx/sharedir.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nyx/sharedir.c b/nyx/sharedir.c index 49cd40924a..57d0dfe245 100644 --- a/nyx/sharedir.c +++ b/nyx/sharedir.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -55,9 +56,12 @@ static char *sharedir_scan(sharedir_t *self, const char *file) * Agent is not under our control, but lets roughly constrain * it to anything stored in or linked from sharedir */ - chdir(self->dir); - char *real_path = realpath(file, NULL); + if (0 != chdir(self->dir)) { + nyx_error("Failed to chdir to sharedir: %s", strerror(errno)); + return NULL; + } + char *real_path = realpath(file, NULL); if (file[0] != '/' && !strstr(file, "/../") && real_path && file_exits(real_path)) { return real_path;