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>
This commit is contained in:
Pekka Paalanen 2015-03-24 15:56:17 +02:00
parent fb7069ee05
commit 49f6d62e9d

View File

@ -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);