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:
@@ -16,6 +16,8 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "parser_helper.h"
|
#include "parser_helper.h"
|
||||||
|
|
||||||
@@ -93,6 +95,7 @@ METHOD(parser_helper_t, file_next, FILE*,
|
|||||||
private_parser_helper_t *this)
|
private_parser_helper_t *this)
|
||||||
{
|
{
|
||||||
parser_helper_file_t *file, *next;
|
parser_helper_file_t *file, *next;
|
||||||
|
struct stat st;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
array_get(this->files, ARRAY_TAIL, &file);
|
array_get(this->files, ARRAY_TAIL, &file);
|
||||||
@@ -112,7 +115,8 @@ METHOD(parser_helper_t, file_next, FILE*,
|
|||||||
.file = fopen(name, "r"),
|
.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);
|
array_insert(this->files, ARRAY_TAIL, next);
|
||||||
return next->file;
|
return next->file;
|
||||||
|
|||||||
Reference in New Issue
Block a user