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.
This commit is contained in:
Tobias Brunner 2020-11-03 10:59:38 +01:00
parent 991e9e5dc9
commit a59842eb95
1 changed files with 5 additions and 1 deletions

View 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;