diff options
author | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2015-03-24 15:56:17 +0200 |
---|---|---|
committer | Pekka Paalanen <pekka.paalanen@collabora.co.uk> | 2015-03-27 09:38:02 +0200 |
commit | 49f6d62e9d4d00b9fb582dfd2b5f824779f8ac59 (patch) | |
tree | b5c482f10bf73c44cdcb8cbc79913b7455b0c5ca /shared | |
parent | fb7069ee0559a89223e9bdac956ccdd413f3784e (diff) | |
download | weston-49f6d62e9d4d00b9fb582dfd2b5f824779f8ac59.tar.gz |
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 <pekka.paalanen@collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Reviewed-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/config-parser.c | 8 |
1 files changed, 8 insertions, 0 deletions
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); |