Blame SOURCES/0086-libmultipath-don-t-return-error-on-invalid-values.patch

c4b4b8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
c4b4b8
From: Benjamin Marzinski <bmarzins@redhat.com>
c4b4b8
Date: Thu, 11 Nov 2021 17:37:05 -0600
c4b4b8
Subject: [PATCH] libmultipath: don't return error on invalid values
c4b4b8
c4b4b8
do_set_int and set_uint return 1 for invalid values. This can cause
c4b4b8
multipath to fail completely, while reading the config. The config
c4b4b8
handlers should only return a non-zero value if there is an internal
c4b4b8
error, not if there is just an invalid value.
c4b4b8
c4b4b8
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
c4b4b8
---
c4b4b8
 libmultipath/dict.c | 64 ++++++++++++++++++---------------------------
c4b4b8
 1 file changed, 25 insertions(+), 39 deletions(-)
c4b4b8
c4b4b8
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
c4b4b8
index b255322e..5a0255b0 100644
c4b4b8
--- a/libmultipath/dict.c
c4b4b8
+++ b/libmultipath/dict.c
c4b4b8
@@ -29,7 +29,7 @@
c4b4b8
 #include "mpath_cmd.h"
c4b4b8
 #include "dict.h"
c4b4b8
 
c4b4b8
-static int
c4b4b8
+static void
c4b4b8
 do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
c4b4b8
 	int line_nr, char *buff)
c4b4b8
 {
c4b4b8
@@ -44,7 +44,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
c4b4b8
 	if (*buff == '\0' || *eptr != '\0') {
c4b4b8
 		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
c4b4b8
 			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
c4b4b8
-		return 1;
c4b4b8
+		return;
c4b4b8
 	}
c4b4b8
 	if (res > max || res < min) {
c4b4b8
 		res = (res > max) ? max : min;
c4b4b8
@@ -53,7 +53,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
c4b4b8
 		(res == max)? "large" : "small", res);
c4b4b8
 	}
c4b4b8
 	*int_ptr = res;
c4b4b8
-	return 0;
c4b4b8
+	return;
c4b4b8
 }
c4b4b8
 
c4b4b8
 static int
c4b4b8
@@ -61,16 +61,15 @@ set_int(vector strvec, void *ptr, int min, int max, const char *file,
c4b4b8
 	int line_nr)
c4b4b8
 {
c4b4b8
 	char *buff;
c4b4b8
-	int rc;
c4b4b8
 
c4b4b8
 	buff = set_value(strvec);
c4b4b8
 	if (!buff)
c4b4b8
 		return 1;
c4b4b8
 
c4b4b8
-	rc = do_set_int(strvec, ptr, min, max, file, line_nr, buff);
c4b4b8
+	do_set_int(strvec, ptr, min, max, file, line_nr, buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
-	return rc;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 static int
c4b4b8
@@ -79,7 +78,6 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 	unsigned int *uint_ptr = (unsigned int *)ptr;
c4b4b8
 	char *buff, *eptr, *p;
c4b4b8
 	unsigned long res;
c4b4b8
-	int rc;
c4b4b8
 
c4b4b8
 	buff = set_value(strvec);
c4b4b8
 	if (!buff)
c4b4b8
@@ -92,17 +90,14 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 	if (eptr > buff)
c4b4b8
 		while (isspace(*eptr))
c4b4b8
 			eptr++;
c4b4b8
-	if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX) {
c4b4b8
+	if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX)
c4b4b8
 		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
c4b4b8
 			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
c4b4b8
-		rc = 1;
c4b4b8
-	} else {
c4b4b8
-		rc = 0;
c4b4b8
+	else
c4b4b8
 		*uint_ptr = res;
c4b4b8
-	}
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
-	return rc;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 static int
c4b4b8
@@ -990,7 +985,6 @@ declare_mp_attr_snprint(gid, print_gid)
c4b4b8
 static int
c4b4b8
 set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 {
c4b4b8
-	int rc = 0;
c4b4b8
 	char * buff;
c4b4b8
 	int *int_ptr = (int *)ptr;
c4b4b8
 
c4b4b8
@@ -1000,11 +994,10 @@ set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 
c4b4b8
 	if (strcmp(buff, "off") == 0)
c4b4b8
 		*int_ptr = UOZ_OFF;
c4b4b8
-	else
c4b4b8
-		rc = do_set_int(strvec, int_ptr, 0, INT_MAX, file, line_nr,
c4b4b8
-				buff);
c4b4b8
-	if (rc == 0 && *int_ptr == 0)
c4b4b8
+	else if (strcmp(buff, "0") == 0)
c4b4b8
 		*int_ptr = UOZ_ZERO;
c4b4b8
+	else
c4b4b8
+		do_set_int(strvec, int_ptr, 1, INT_MAX, file, line_nr, buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
 	return 0;
c4b4b8
@@ -1151,28 +1144,24 @@ max_fds_handler(struct config *conf, vector strvec, const char *file,
c4b4b8
 		int line_nr)
c4b4b8
 {
c4b4b8
 	char * buff;
c4b4b8
-	int r = 0, max_fds;
c4b4b8
+	int max_fds;
c4b4b8
 
c4b4b8
 	buff = set_value(strvec);
c4b4b8
 
c4b4b8
 	if (!buff)
c4b4b8
 		return 1;
c4b4b8
 
c4b4b8
-	r = get_sys_max_fds(&max_fds);
c4b4b8
-	if (r) {
c4b4b8
-		/* Assume safe limit */
c4b4b8
-		max_fds = 4096;
c4b4b8
-	}
c4b4b8
-	if (!strcmp(buff, "max")) {
c4b4b8
+	if (get_sys_max_fds(&max_fds) != 0)
c4b4b8
+		max_fds = 4096;  /* Assume safe limit */
c4b4b8
+	if (!strcmp(buff, "max"))
c4b4b8
 		conf->max_fds = max_fds;
c4b4b8
-		r = 0;
c4b4b8
-	} else
c4b4b8
-		r = do_set_int(strvec, &conf->max_fds, 0, max_fds, file,
c4b4b8
-			       line_nr, buff);
c4b4b8
+	else
c4b4b8
+		do_set_int(strvec, &conf->max_fds, 0, max_fds, file, line_nr,
c4b4b8
+			   buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
 
c4b4b8
-	return r;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 static int
c4b4b8
@@ -1238,7 +1227,6 @@ declare_mp_snprint(rr_weight, print_rr_weight)
c4b4b8
 static int
c4b4b8
 set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 {
c4b4b8
-	int rc = 0;
c4b4b8
 	int *int_ptr = (int *)ptr;
c4b4b8
 	char * buff;
c4b4b8
 
c4b4b8
@@ -1253,11 +1241,11 @@ set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 	else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
c4b4b8
 		*int_ptr = -FAILBACK_FOLLOWOVER;
c4b4b8
 	else
c4b4b8
-		rc = do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
c4b4b8
+		do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
 
c4b4b8
-	return rc;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 int
c4b4b8
@@ -1289,7 +1277,6 @@ declare_mp_snprint(pgfailback, print_pgfailback)
c4b4b8
 static int
c4b4b8
 no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 {
c4b4b8
-	int rc = 0;
c4b4b8
 	int *int_ptr = (int *)ptr;
c4b4b8
 	char * buff;
c4b4b8
 
c4b4b8
@@ -1302,10 +1289,10 @@ no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 	else if (!strcmp(buff, "queue"))
c4b4b8
 		*int_ptr = NO_PATH_RETRY_QUEUE;
c4b4b8
 	else
c4b4b8
-		rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
c4b4b8
+		do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
-	return rc;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 int
c4b4b8
@@ -1453,7 +1440,6 @@ snprint_mp_reservation_key (struct config *conf, char * buff, int len,
c4b4b8
 static int
c4b4b8
 set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 {
c4b4b8
-	int rc =0;
c4b4b8
 	int *int_ptr = (int *)ptr;
c4b4b8
 	char * buff;
c4b4b8
 
c4b4b8
@@ -1464,10 +1450,10 @@ set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
c4b4b8
 	if (!strcmp(buff, "no") || !strcmp(buff, "0"))
c4b4b8
 		*int_ptr = NU_NO;
c4b4b8
 	else
c4b4b8
-		rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
c4b4b8
+		do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
c4b4b8
 
c4b4b8
 	FREE(buff);
c4b4b8
-	return rc;
c4b4b8
+	return 0;
c4b4b8
 }
c4b4b8
 
c4b4b8
 int