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

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