]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
parser-helper: Don't attempt to open anything but regular files
authorTobias Brunner <tobias@strongswan.org>
Tue, 3 Nov 2020 09:59:38 +0000 (10:59 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 4 Nov 2020 09:06:46 +0000 (10:06 +0100)
A crash could be provoked e.g. via STRONGSWAN_CONF=. or any other
path to a directory.

src/libstrongswan/utils/parser_helper.c

index 3ed22b61de1c203e0314ced7f801fdae8583924e..bcda3b106d1f02997f11bd989583cc377228a8e8 100644 (file)
@@ -16,6 +16,8 @@
 #include <limits.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #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;