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

e65fa3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e65fa3
From: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
Date: Thu, 11 Nov 2021 17:37:05 -0600
e65fa3
Subject: [PATCH] libmultipath: don't return error on invalid values
e65fa3
e65fa3
do_set_int and set_uint return 1 for invalid values. This can cause
e65fa3
multipath to fail completely, while reading the config. The config
e65fa3
handlers should only return a non-zero value if there is an internal
e65fa3
error, not if there is just an invalid value.
e65fa3
e65fa3
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
e65fa3
---
e65fa3
 libmultipath/dict.c | 64 ++++++++++++++++++---------------------------
e65fa3
 1 file changed, 25 insertions(+), 39 deletions(-)
e65fa3
e65fa3
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
e65fa3
index c534d703..1b75be47 100644
e65fa3
--- a/libmultipath/dict.c
e65fa3
+++ b/libmultipath/dict.c
e65fa3
@@ -30,7 +30,7 @@
e65fa3
 #include "dict.h"
e65fa3
 #include "strbuf.h"
e65fa3
 
e65fa3
-static int
e65fa3
+static void
e65fa3
 do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
e65fa3
 	int line_nr, char *buff)
e65fa3
 {
e65fa3
@@ -45,7 +45,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
e65fa3
 	if (*buff == '\0' || *eptr != '\0') {
e65fa3
 		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
e65fa3
 			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
e65fa3
-		return 1;
e65fa3
+		return;
e65fa3
 	}
e65fa3
 	if (res > max || res < min) {
e65fa3
 		res = (res > max) ? max : min;
e65fa3
@@ -54,7 +54,7 @@ do_set_int(vector strvec, void *ptr, int min, int max, const char *file,
e65fa3
 		(res == max)? "large" : "small", res);
e65fa3
 	}
e65fa3
 	*int_ptr = res;
e65fa3
-	return 0;
e65fa3
+	return;
e65fa3
 }
e65fa3
 
e65fa3
 static int
e65fa3
@@ -62,16 +62,15 @@ set_int(vector strvec, void *ptr, int min, int max, const char *file,
e65fa3
 	int line_nr)
e65fa3
 {
e65fa3
 	char *buff;
e65fa3
-	int rc;
e65fa3
 
e65fa3
 	buff = set_value(strvec);
e65fa3
 	if (!buff)
e65fa3
 		return 1;
e65fa3
 
e65fa3
-	rc = do_set_int(strvec, ptr, min, max, file, line_nr, buff);
e65fa3
+	do_set_int(strvec, ptr, min, max, file, line_nr, buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
-	return rc;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 static int
e65fa3
@@ -80,7 +79,6 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 	unsigned int *uint_ptr = (unsigned int *)ptr;
e65fa3
 	char *buff, *eptr, *p;
e65fa3
 	unsigned long res;
e65fa3
-	int rc;
e65fa3
 
e65fa3
 	buff = set_value(strvec);
e65fa3
 	if (!buff)
e65fa3
@@ -93,17 +91,14 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 	if (eptr > buff)
e65fa3
 		while (isspace(*eptr))
e65fa3
 			eptr++;
e65fa3
-	if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX) {
e65fa3
+	if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX)
e65fa3
 		condlog(1, "%s line %d, invalid value for %s: \"%s\"",
e65fa3
 			file, line_nr, (char*)VECTOR_SLOT(strvec, 0), buff);
e65fa3
-		rc = 1;
e65fa3
-	} else {
e65fa3
-		rc = 0;
e65fa3
+	else
e65fa3
 		*uint_ptr = res;
e65fa3
-	}
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
-	return rc;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 static int
e65fa3
@@ -954,7 +949,6 @@ declare_mp_attr_snprint(gid, print_gid)
e65fa3
 static int
e65fa3
 set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 {
e65fa3
-	int rc = 0;
e65fa3
 	char * buff;
e65fa3
 	int *int_ptr = (int *)ptr;
e65fa3
 
e65fa3
@@ -964,11 +958,10 @@ set_undef_off_zero(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 
e65fa3
 	if (strcmp(buff, "off") == 0)
e65fa3
 		*int_ptr = UOZ_OFF;
e65fa3
-	else
e65fa3
-		rc = do_set_int(strvec, int_ptr, 0, INT_MAX, file, line_nr,
e65fa3
-				buff);
e65fa3
-	if (rc == 0 && *int_ptr == 0)
e65fa3
+	else if (strcmp(buff, "0") == 0)
e65fa3
 		*int_ptr = UOZ_ZERO;
e65fa3
+	else
e65fa3
+		do_set_int(strvec, int_ptr, 1, INT_MAX, file, line_nr, buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
 	return 0;
e65fa3
@@ -1114,28 +1107,24 @@ max_fds_handler(struct config *conf, vector strvec, const char *file,
e65fa3
 		int line_nr)
e65fa3
 {
e65fa3
 	char * buff;
e65fa3
-	int r = 0, max_fds;
e65fa3
+	int max_fds;
e65fa3
 
e65fa3
 	buff = set_value(strvec);
e65fa3
 
e65fa3
 	if (!buff)
e65fa3
 		return 1;
e65fa3
 
e65fa3
-	r = get_sys_max_fds(&max_fds);
e65fa3
-	if (r) {
e65fa3
-		/* Assume safe limit */
e65fa3
-		max_fds = 4096;
e65fa3
-	}
e65fa3
-	if (!strcmp(buff, "max")) {
e65fa3
+	if (get_sys_max_fds(&max_fds) != 0)
e65fa3
+		max_fds = 4096;  /* Assume safe limit */
e65fa3
+	if (!strcmp(buff, "max"))
e65fa3
 		conf->max_fds = max_fds;
e65fa3
-		r = 0;
e65fa3
-	} else
e65fa3
-		r = do_set_int(strvec, &conf->max_fds, 0, max_fds, file,
e65fa3
-			       line_nr, buff);
e65fa3
+	else
e65fa3
+		do_set_int(strvec, &conf->max_fds, 0, max_fds, file, line_nr,
e65fa3
+			   buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
 
e65fa3
-	return r;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 static int
e65fa3
@@ -1201,7 +1190,6 @@ declare_mp_snprint(rr_weight, print_rr_weight)
e65fa3
 static int
e65fa3
 set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 {
e65fa3
-	int rc = 0;
e65fa3
 	int *int_ptr = (int *)ptr;
e65fa3
 	char * buff;
e65fa3
 
e65fa3
@@ -1216,11 +1204,11 @@ set_pgfailback(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 	else if (strlen(buff) == 10 && !strcmp(buff, "followover"))
e65fa3
 		*int_ptr = -FAILBACK_FOLLOWOVER;
e65fa3
 	else
e65fa3
-		rc = do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
e65fa3
+		do_set_int(strvec, ptr, 0, INT_MAX, file, line_nr, buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
 
e65fa3
-	return rc;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 int
e65fa3
@@ -1252,7 +1240,6 @@ declare_mp_snprint(pgfailback, print_pgfailback)
e65fa3
 static int
e65fa3
 no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 {
e65fa3
-	int rc = 0;
e65fa3
 	int *int_ptr = (int *)ptr;
e65fa3
 	char * buff;
e65fa3
 
e65fa3
@@ -1265,10 +1252,10 @@ no_path_retry_helper(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 	else if (!strcmp(buff, "queue"))
e65fa3
 		*int_ptr = NO_PATH_RETRY_QUEUE;
e65fa3
 	else
e65fa3
-		rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
e65fa3
+		do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
-	return rc;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 int
e65fa3
@@ -1413,7 +1400,6 @@ snprint_mp_reservation_key (struct config *conf, struct strbuf *buff,
e65fa3
 static int
e65fa3
 set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 {
e65fa3
-	int rc =0;
e65fa3
 	int *int_ptr = (int *)ptr;
e65fa3
 	char * buff;
e65fa3
 
e65fa3
@@ -1424,10 +1410,10 @@ set_off_int_undef(vector strvec, void *ptr, const char *file, int line_nr)
e65fa3
 	if (!strcmp(buff, "no") || !strcmp(buff, "0"))
e65fa3
 		*int_ptr = NU_NO;
e65fa3
 	else
e65fa3
-		rc = do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
e65fa3
+		do_set_int(strvec, ptr, 1, INT_MAX, file, line_nr, buff);
e65fa3
 
e65fa3
 	FREE(buff);
e65fa3
-	return rc;
e65fa3
+	return 0;
e65fa3
 }
e65fa3
 
e65fa3
 int