From 49f6d62e9d4d00b9fb582dfd2b5f824779f8ac59 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Tue, 24 Mar 2015 15:56:17 +0200 Subject: [PATCH] shared: fail reading a directory as a config file open() will happily open directories and other non-normal files. Attempting to parse them as config files makes no sense, so check that the opened file is indeed a regular file. Signed-off-by: Pekka Paalanen Reviewed-by: Jonny Lamb Reviewed-by: Nobuhiko Tanibata Reviewed-by: Bryce Harrington --- shared/config-parser.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/config-parser.c b/shared/config-parser.c index 4542ca61..ff6814ce 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -326,6 +326,7 @@ weston_config_parse(const char *name) { FILE *fp; char line[512], *p; + struct stat filestat; struct weston_config *config; struct weston_config_section *section = NULL; int i, fd; @@ -342,6 +343,13 @@ weston_config_parse(const char *name) return NULL; } + if (fstat(fd, &filestat) < 0 || + !S_ISREG(filestat.st_mode)) { + close(fd); + free(config); + return NULL; + } + fp = fdopen(fd, "r"); if (fp == NULL) { free(config);