From a59842eb9525e428d383cf54d336dba2d91f2941 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 3 Nov 2020 10:59:38 +0100 Subject: [PATCH] parser-helper: Don't attempt to open anything but regular files A crash could be provoked e.g. via STRONGSWAN_CONF=. or any other path to a directory. --- src/libstrongswan/utils/parser_helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/utils/parser_helper.c b/src/libstrongswan/utils/parser_helper.c index 3ed22b61de..bcda3b106d 100644 --- a/src/libstrongswan/utils/parser_helper.c +++ b/src/libstrongswan/utils/parser_helper.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include "parser_helper.h" @@ -93,6 +95,7 @@ METHOD(parser_helper_t, file_next, FILE*, private_parser_helper_t *this) { parser_helper_file_t *file, *next; + struct stat st; char *name; array_get(this->files, ARRAY_TAIL, &file); @@ -112,7 +115,8 @@ METHOD(parser_helper_t, file_next, FILE*, .file = fopen(name, "r"), ); - if (next->file) + if (next->file && fstat(fileno(next->file), &st) == 0 && + S_ISREG(st.st_mode)) { array_insert(this->files, ARRAY_TAIL, next); return next->file; -- 2.47.2