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

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