mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-10-07 05:25:01 +00:00
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:
parent
fb7069ee05
commit
49f6d62e9d
|
@ -326,6 +326,7 @@ weston_config_parse(const char *name)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[512], *p;
|
char line[512], *p;
|
||||||
|
struct stat filestat;
|
||||||
struct weston_config *config;
|
struct weston_config *config;
|
||||||
struct weston_config_section *section = NULL;
|
struct weston_config_section *section = NULL;
|
||||||
int i, fd;
|
int i, fd;
|
||||||
|
@ -342,6 +343,13 @@ weston_config_parse(const char *name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fstat(fd, &filestat) < 0 ||
|
||||||
|
!S_ISREG(filestat.st_mode)) {
|
||||||
|
close(fd);
|
||||||
|
free(config);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
fp = fdopen(fd, "r");
|
fp = fdopen(fd, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
free(config);
|
free(config);
|
||||||
|
|
Loading…
Reference in a new issue