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

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