@@ -323,6 +323,7 @@ static void read_config(void)
int conf_dirfd;
DIR *conf_dir;
struct dirent *dent;
+ struct stat buf;
conf_dirfd = open(IBV_CONFIG_DIR, O_RDONLY | O_CLOEXEC);
if (conf_dirfd == -1) {
@@ -331,12 +332,23 @@ static void read_config(void)
return;
}
+ if (fstat(conf_dirfd, &buf)) {
+ fprintf(stderr, PFX "Warning: couldn't stat config directory '%s'.\n",
+ IBV_CONFIG_DIR);
+ goto out;
+ }
+
+ if (!S_ISDIR(buf.st_mode)) {
+ fprintf(stderr, PFX "Warning: invalid config directory '%s'.\n",
+ IBV_CONFIG_DIR);
+ goto out;
+ }
+
conf_dir = fdopendir(conf_dirfd);
if (!conf_dir) {
fprintf(stderr, PFX "Warning: couldn't open config directory '%s'.\n",
IBV_CONFIG_DIR);
- close(conf_dirfd);
- return;
+ goto out;
}
while ((dent = readdir(conf_dir))) {
@@ -351,6 +363,11 @@ static void read_config(void)
}
closedir(conf_dir);
+
+ return;
+
+out:
+ close(conf_dirfd);
}
static struct ibv_device *try_driver(struct ibv_driver *driver,
After opening the directory, call fstat() on directory file descriptor so that its parameters can be checked later. Signed-off-by: Yann Droneaud <ydroneaud@opteya.com> --- src/init.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)