Blame SOURCES/0085-libmultipath-cleanup-invalid-config-handling.patch

adddbf
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
adddbf
From: Benjamin Marzinski <bmarzins@redhat.com>
adddbf
Date: Mon, 4 Oct 2021 16:52:55 -0500
adddbf
Subject: [PATCH] libmultipath: cleanup invalid config handling
adddbf
adddbf
Add error reporting to the remaining config handlers. If the value is
adddbf
invalid, do not change the existing config option's value. Also print
adddbf
an error whenever 0 is returned for an invalid value. When the handler
adddbf
returns 1, config processing already fails with an error message.
adddbf
adddbf
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
adddbf
---
adddbf
 libmultipath/dict.c | 73 +++++++++++++++++++++++++++++++--------------
adddbf
 1 file changed, 51 insertions(+), 22 deletions(-)
adddbf
adddbf
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
adddbf
index 6330836a..b255322e 100644
adddbf
--- a/libmultipath/dict.c
adddbf
+++ b/libmultipath/dict.c
adddbf
@@ -212,8 +212,11 @@ set_yes_no(vector strvec, void *ptr, const char *file, int line_nr)
adddbf
 
adddbf
 	if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
adddbf
 		*int_ptr = YN_YES;
adddbf
-	else
adddbf
+	else if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
adddbf
 		*int_ptr = YN_NO;
adddbf
+	else
adddbf
+		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
adddbf
+			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
adddbf
 
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
@@ -234,7 +237,8 @@ set_yes_no_undef(vector strvec, void *ptr, const char *file, int line_nr)
adddbf
 	else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
adddbf
 		*int_ptr = YNU_YES;
adddbf
 	else
adddbf
-		*int_ptr = YNU_UNDEF;
adddbf
+		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
adddbf
+			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
adddbf
 
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
@@ -523,9 +527,6 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
adddbf
 	char *buff;
adddbf
 	int i;
adddbf
 
adddbf
-	if (set_yes_no_undef(strvec, &conf->find_multipaths, file, line_nr) == 0 && conf->find_multipaths != FIND_MULTIPATHS_UNDEF)
adddbf
-		return 0;
adddbf
-
adddbf
 	buff = set_value(strvec);
adddbf
 	if (!buff)
adddbf
 		return 1;
adddbf
@@ -538,9 +539,14 @@ def_find_multipaths_handler(struct config *conf, vector strvec,
adddbf
 		}
adddbf
 	}
adddbf
 
adddbf
-	if (conf->find_multipaths == YNU_UNDEF) {
adddbf
-		condlog(0, "illegal value for find_multipaths: %s", buff);
adddbf
-		conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
adddbf
+	if (i >= __FIND_MULTIPATHS_LAST) {
adddbf
+		if (strcmp(buff, "no") == 0 || strcmp(buff, "0") == 0)
adddbf
+			conf->find_multipaths = FIND_MULTIPATHS_OFF;
adddbf
+		else if (strcmp(buff, "yes") == 0 || strcmp(buff, "1") == 0)
adddbf
+			conf->find_multipaths = FIND_MULTIPATHS_ON;
adddbf
+		else
adddbf
+			condlog(1, "%s line %d, invalid value for find_multipaths: \"%s\"",
adddbf
+				file, line_nr, buff);
adddbf
 	}
adddbf
 
adddbf
 	FREE(buff);
adddbf
@@ -591,8 +597,10 @@ static int uid_attrs_handler(struct config *conf, vector strvec,
adddbf
 	if (!val)
adddbf
 		return 1;
adddbf
 	if (parse_uid_attrs(val, conf))
adddbf
-		condlog(1, "error parsing uid_attrs: \"%s\"", val);
adddbf
-	condlog(3, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
adddbf
+		condlog(1, "%s line %d,error parsing uid_attrs: \"%s\"", file,
adddbf
+			line_nr, val);
adddbf
+	else
adddbf
+		condlog(4, "parsed %d uid_attrs", VECTOR_SIZE(&conf->uid_attrs));
adddbf
 	FREE(val);
adddbf
 	return 0;
adddbf
 }
adddbf
@@ -811,8 +819,11 @@ def_config_dir_handler(struct config *conf, vector strvec, const char *file,
adddbf
 		       int line_nr)
adddbf
 {
adddbf
 	/* this is only valid in the main config file */
adddbf
-	if (conf->processed_main_config)
adddbf
+	if (conf->processed_main_config) {
adddbf
+		condlog(1, "%s line %d, config_dir option only valid in /etc/multipath.conf",
adddbf
+			file, line_nr);
adddbf
 		return 0;
adddbf
+	}
adddbf
 	return set_path(strvec, &conf->config_dir, file, line_nr);
adddbf
 }
adddbf
 declare_def_snprint(config_dir, print_str)
adddbf
@@ -872,7 +883,9 @@ set_mode(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
adddbf
 	if (sscanf(buff, "%o", &mode) == 1 && mode <= 0777) {
adddbf
 		*flags |= (1 << ATTR_MODE);
adddbf
 		*mode_ptr = mode;
adddbf
-	}
adddbf
+	} else
adddbf
+		condlog(1, "%s line %d, invalid value for mode: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
@@ -897,7 +910,9 @@ set_uid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
adddbf
 	else if (sscanf(buff, "%u", &uid) == 1){
adddbf
 		*flags |= (1 << ATTR_UID);
adddbf
 		*uid_ptr = uid;
adddbf
-	}
adddbf
+	} else
adddbf
+		condlog(1, "%s line %d, invalid value for uid: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
@@ -923,7 +938,9 @@ set_gid(vector strvec, void *ptr, int *flags, const char *file, int line_nr)
adddbf
 	else if (sscanf(buff, "%u", &gid) == 1){
adddbf
 		*flags |= (1 << ATTR_GID);
adddbf
 		*gid_ptr = gid;
adddbf
-	}
adddbf
+	} else
adddbf
+		condlog(1, "%s line %d, invalid value for gid: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
 }
adddbf
@@ -1026,7 +1043,8 @@ set_dev_loss(vector strvec, void *ptr, const char *file, int line_nr)
adddbf
 	if (!strcmp(buff, "infinity"))
adddbf
 		*uint_ptr = MAX_DEV_LOSS_TMO;
adddbf
 	else if (sscanf(buff, "%u", uint_ptr) != 1)
adddbf
-		*uint_ptr = 0;
adddbf
+		condlog(1, "%s line %d, invalid value for dev_loss_tmo: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 
adddbf
 	FREE(buff);
adddbf
 	return 0;
adddbf
@@ -1060,13 +1078,19 @@ static int
adddbf
 set_pgpolicy(vector strvec, void *ptr, const char *file, int line_nr)
adddbf
 {
adddbf
 	char * buff;
adddbf
+	int policy;
adddbf
 	int *int_ptr = (int *)ptr;
adddbf
 
adddbf
 	buff = set_value(strvec);
adddbf
 	if (!buff)
adddbf
 		return 1;
adddbf
 
adddbf
-	*int_ptr = get_pgpolicy_id(buff);
adddbf
+	policy = get_pgpolicy_id(buff);
adddbf
+	if (policy != IOPOLICY_UNDEF)
adddbf
+		*int_ptr = policy;
adddbf
+	else
adddbf
+		condlog(1, "%s line %d, invalid value for path_grouping_policy: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 	FREE(buff);
adddbf
 
adddbf
 	return 0;
adddbf
@@ -1179,10 +1203,11 @@ set_rr_weight(vector strvec, void *ptr, const char *file, int line_nr)
adddbf
 
adddbf
 	if (!strcmp(buff, "priorities"))
adddbf
 		*int_ptr = RR_WEIGHT_PRIO;
adddbf
-
adddbf
-	if (!strcmp(buff, "uniform"))
adddbf
+	else if (!strcmp(buff, "uniform"))
adddbf
 		*int_ptr = RR_WEIGHT_NONE;
adddbf
-
adddbf
+	else
adddbf
+		condlog(1, "%s line %d, invalid value for rr_weight: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 	FREE(buff);
adddbf
 
adddbf
 	return 0;
adddbf
@@ -1318,10 +1343,13 @@ def_log_checker_err_handler(struct config *conf, vector strvec,
adddbf
 	if (!buff)
adddbf
 		return 1;
adddbf
 
adddbf
-	if (strlen(buff) == 4 && !strcmp(buff, "once"))
adddbf
+	if (!strcmp(buff, "once"))
adddbf
 		conf->log_checker_err = LOG_CHKR_ERR_ONCE;
adddbf
-	else if (strlen(buff) == 6 && !strcmp(buff, "always"))
adddbf
+	else if (!strcmp(buff, "always"))
adddbf
 		conf->log_checker_err = LOG_CHKR_ERR_ALWAYS;
adddbf
+	else
adddbf
+		condlog(1, "%s line %d, invalid value for log_checker_err: \"%s\"",
adddbf
+			file, line_nr, buff);
adddbf
 
adddbf
 	free(buff);
adddbf
 	return 0;
adddbf
@@ -1585,7 +1613,8 @@ hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,
adddbf
 			goto out;
adddbf
 		}
adddbf
 	}
adddbf
-	hwe->vpd_vendor_id = 0;
adddbf
+	condlog(1, "%s line %d, invalid value for vpd_vendor: \"%s\"",
adddbf
+		file, line_nr, buff);
adddbf
 out:
adddbf
 	FREE(buff);
adddbf
 	return 0;