[PATCH weston 3/6] shared: fail reading a directory as a config file
Pekka Paalanen
ppaalanen at gmail.com
Tue Mar 24 06:56:17 PDT 2015
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
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 at collabora.co.uk>
---
shared/config-parser.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 4542ca6..ff6814c 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);
--
2.0.5
More information about the wayland-devel
mailing list