@@ -243,6 +243,19 @@ static void read_config_file(const char *path)
char *field;
size_t buflen = 0;
ssize_t len;
+ struct stat buf;
+
+ if (stat(path, &buf)) {
+ fprintf(stderr, PFX "Warning: couldn't stat config file '%s'.\n",
+ path);
+ return;
+ }
+
+ if (!S_ISREG(buf.st_mode)) {
+ fprintf(stderr, PFX "Warning: invalid config file '%s'.\n",
+ path);
+ return;
+ }
conf = fopen(path, "r" STREAM_CLOEXEC);
if (!conf) {
@@ -314,7 +327,6 @@ static void read_config(void)
}
while ((dent = readdir(conf_dir))) {
- struct stat buf;
if (dent->d_name[0] == '.')
continue;
@@ -328,17 +340,8 @@ static void read_config(void)
goto out;
}
- if (stat(path, &buf)) {
- fprintf(stderr, PFX "Warning: couldn't stat config file '%s'.\n",
- path);
- goto next;
- }
-
- if (!S_ISREG(buf.st_mode))
- goto next;
-
read_config_file(path);
-next:
+
free(path);
}
Check the configuration file inside the function parsing it. Signed-off-by: Yann Droneaud <ydroneaud@opteya.com> --- src/init.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)