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;