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

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