Skip to contentSkip to conversation

libmultipath: fix files read from config_dir

PATCH In review Enzo Matsumiya 2 participants 2 messages Feb 7, 2020 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libmultipath: fix files read from config_dir

If config_dir contains a file named, for example, "some.conf.backup", this file will still be loaded by multipath because process_config_dir() (libmultipath/config.c) uses strstr() to check for the ".conf" extension, but that doesn't guarantee that ".conf" is at the end of the filename.

This patch will make sure that only files ending in ".conf" are loaded from config_dir.

This is to comply with config_dir entry description in man 5 multipath.conf.

---
 libmultipath/config.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
libmultipath/config.c +4 -1
index 20e3b8bf..4785ade8 100644
@@ -671,8 +671,11 @@ process_config_dir(struct config *conf, vector keywords, char *dir)
 	sr.n = n;
 	pthread_cleanup_push_cast(free_scandir_result, &sr);
 	for (i = 0; i < n; i++) {
-		if (!strstr(namelist[i]->d_name, ".conf"))
+		char *ext = strrchr(namelist[i]->d_name, '.');
+
+		if (!ext || strcmp(ext, ".conf"))
 			continue;
+
 		old_hwtable_size = VECTOR_SIZE(conf->hwtable);
 		snprintf(path, LINE_MAX, "%s/%s", dir, namelist[i]->d_name);
 		path[LINE_MAX-1] = '\0';
Signature · 1 line
2.16.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Enzo Matsumiya

If config_dir contains a file named, for example, "some.conf.backup", this file
will still be loaded by multipath because process_config_dir() (libmultipath/config.c) uses strstr() to check for the ".conf" extension, but
that doesn't guarantee that ".conf" is at the end of the filename.

This patch will make sure that only files ending in ".conf" are loaded from
config_dir.

This is to comply with config_dir entry description in man 5 multipath.conf.

---
 libmultipath/config.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
libmultipath/config.c +4 -1
index 20e3b8bf..4785ade8 100644
@@ -671,8 +671,11 @@ process_config_dir(struct config *conf, vector
 keywords, char *dir)
 	sr.n = n;
 	pthread_cleanup_push_cast(free_scandir_result, &sr);
 	for (i = 0; i < n; i++) {
-		if (!strstr(namelist[i]->d_name, ".conf"))
+		char *ext = strrchr(namelist[i]->d_name, '.');
+
+		if (!ext || strcmp(ext, ".conf"))
 			continue;
+
 		old_hwtable_size = VECTOR_SIZE(conf->hwtable);
 		snprintf(path, LINE_MAX, "%s/%s", dir, namelist[i]-
Quoted 1 line

d_name);

Quoted 1 line

path[LINE_MAX-1] = '\0';

Signature · 4 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107
SUSE  Software Solutions Germany GmbH
HRB 36809, AG Nürnberg GF: Felix
Imendörffer