|
|
adddbf |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
adddbf |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
adddbf |
Date: Tue, 28 Sep 2021 15:59:19 -0500
|
|
|
adddbf |
Subject: [PATCH] libmultipath: make set_int take a range for valid values
|
|
|
adddbf |
|
|
|
adddbf |
If a value outside of the valid range is passed to set_int, it caps the
|
|
|
adddbf |
value at appropriate limit, and issues a warning.
|
|
|
adddbf |
|
|
|
adddbf |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
adddbf |
---
|
|
|
adddbf |
libmultipath/dict.c | 121 +++++++++++++++++++++++++++-----------------
|
|
|
adddbf |
1 file changed, 75 insertions(+), 46 deletions(-)
|
|
|
adddbf |
|
|
|
adddbf |
diff --git a/libmultipath/dict.c b/libmultipath/dict.c
|
|
|
adddbf |
index a8872da7..686f4d5c 100644
|
|
|
adddbf |
--- a/libmultipath/dict.c
|
|
|
adddbf |
+++ b/libmultipath/dict.c
|
|
|
adddbf |
@@ -28,7 +28,8 @@
|
|
|
adddbf |
#include "dict.h"
|
|
|
adddbf |
|
|
|
adddbf |
static int
|
|
|
adddbf |
-set_int(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
+set_int(vector strvec, void *ptr, int min, int max, const char *file,
|
|
|
adddbf |
+ int line_nr)
|
|
|
adddbf |
{
|
|
|
adddbf |
int *int_ptr = (int *)ptr;
|
|
|
adddbf |
char *buff, *eptr;
|
|
|
adddbf |
@@ -43,11 +44,17 @@ set_int(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' || res > INT_MAX || res < INT_MIN) {
|
|
|
adddbf |
- condlog(1, "%s: invalid value for %s: \"%s\"",
|
|
|
adddbf |
- __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
|
|
|
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 |
rc = 1;
|
|
|
adddbf |
} else {
|
|
|
adddbf |
+ if (res > max || res < min) {
|
|
|
adddbf |
+ res = (res > max) ? max : min;
|
|
|
adddbf |
+ condlog(1, "%s line %d, value for %s too %s, capping at %ld",
|
|
|
adddbf |
+ file, line_nr, (char*)VECTOR_SLOT(strvec, 0),
|
|
|
adddbf |
+ (res == max)? "large" : "small", res);
|
|
|
adddbf |
+ }
|
|
|
adddbf |
rc = 0;
|
|
|
adddbf |
*int_ptr = res;
|
|
|
adddbf |
}
|
|
|
adddbf |
@@ -76,8 +83,8 @@ set_uint(vector strvec, void *ptr, const char *file, int line_nr)
|
|
|
adddbf |
while (isspace(*eptr))
|
|
|
adddbf |
eptr++;
|
|
|
adddbf |
if (*buff == '\0' || *eptr != '\0' || !isdigit(*p) || res > UINT_MAX) {
|
|
|
adddbf |
- condlog(1, "%s: invalid value for %s: \"%s\"",
|
|
|
adddbf |
- __func__, (char*)VECTOR_SLOT(strvec, 0), buff);
|
|
|
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 |
@@ -246,6 +253,14 @@ def_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
return function (strvec, &conf->option, file, line_nr); \
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
+#define declare_def_range_handler(option, minval, maxval) \
|
|
|
adddbf |
+static int \
|
|
|
adddbf |
+def_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
+ const char *file, int line_nr) \
|
|
|
adddbf |
+{ \
|
|
|
adddbf |
+ return set_int(strvec, &conf->option, minval, maxval, file, line_nr); \
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
#define declare_def_snprint(option, function) \
|
|
|
adddbf |
static int \
|
|
|
adddbf |
snprint_def_ ## option (struct config *conf, char * buff, int len, \
|
|
|
adddbf |
@@ -287,6 +302,18 @@ hw_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
return function (strvec, &hwe->option, file, line_nr); \
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
+#define declare_hw_range_handler(option, minval, maxval) \
|
|
|
adddbf |
+static int \
|
|
|
adddbf |
+hw_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
+ const char *file, int line_nr) \
|
|
|
adddbf |
+{ \
|
|
|
adddbf |
+ struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable); \
|
|
|
adddbf |
+ if (!hwe) \
|
|
|
adddbf |
+ return 1; \
|
|
|
adddbf |
+ return set_int(strvec, &hwe->option, minval, maxval, file, line_nr); \
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
+
|
|
|
adddbf |
#define declare_hw_snprint(option, function) \
|
|
|
adddbf |
static int \
|
|
|
adddbf |
snprint_hw_ ## option (struct config *conf, char * buff, int len, \
|
|
|
adddbf |
@@ -306,6 +333,17 @@ ovr_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
return function (strvec, &conf->overrides->option, file, line_nr); \
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
+#define declare_ovr_range_handler(option, minval, maxval) \
|
|
|
adddbf |
+static int \
|
|
|
adddbf |
+ovr_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
+ const char *file, int line_nr) \
|
|
|
adddbf |
+{ \
|
|
|
adddbf |
+ if (!conf->overrides) \
|
|
|
adddbf |
+ return 1; \
|
|
|
adddbf |
+ return set_int(strvec, &conf->overrides->option, minval, maxval, \
|
|
|
adddbf |
+ file, line_nr); \
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
#define declare_ovr_snprint(option, function) \
|
|
|
adddbf |
static int \
|
|
|
adddbf |
snprint_ovr_ ## option (struct config *conf, char * buff, int len, \
|
|
|
adddbf |
@@ -325,6 +363,17 @@ mp_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
return function (strvec, &mpe->option, file, line_nr); \
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
+#define declare_mp_range_handler(option, minval, maxval) \
|
|
|
adddbf |
+static int \
|
|
|
adddbf |
+mp_ ## option ## _handler (struct config *conf, vector strvec, \
|
|
|
adddbf |
+ const char *file, int line_nr) \
|
|
|
adddbf |
+{ \
|
|
|
adddbf |
+ struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable); \
|
|
|
adddbf |
+ if (!mpe) \
|
|
|
adddbf |
+ return 1; \
|
|
|
adddbf |
+ return set_int(strvec, &mpe->option, minval, maxval, file, line_nr); \
|
|
|
adddbf |
+}
|
|
|
adddbf |
+
|
|
|
adddbf |
#define declare_mp_snprint(option, function) \
|
|
|
adddbf |
static int \
|
|
|
adddbf |
snprint_mp_ ## option (struct config *conf, char * buff, int len, \
|
|
|
adddbf |
@@ -351,7 +400,7 @@ declare_def_snprint(checkint, print_int)
|
|
|
adddbf |
declare_def_handler(max_checkint, set_uint)
|
|
|
adddbf |
declare_def_snprint(max_checkint, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(verbosity, set_int)
|
|
|
adddbf |
+declare_def_range_handler(verbosity, 0, MAX_VERBOSITY)
|
|
|
adddbf |
declare_def_snprint(verbosity, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(reassign_maps, set_yes_no)
|
|
|
adddbf |
@@ -528,22 +577,22 @@ declare_ovr_snprint(checker_name, print_str)
|
|
|
adddbf |
declare_hw_handler(checker_name, set_str)
|
|
|
adddbf |
declare_hw_snprint(checker_name, print_str)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(minio, set_int)
|
|
|
adddbf |
+declare_def_range_handler(minio, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint_defint(minio, print_int, DEFAULT_MINIO)
|
|
|
adddbf |
-declare_ovr_handler(minio, set_int)
|
|
|
adddbf |
+declare_ovr_range_handler(minio, 0, INT_MAX)
|
|
|
adddbf |
declare_ovr_snprint(minio, print_nonzero)
|
|
|
adddbf |
-declare_hw_handler(minio, set_int)
|
|
|
adddbf |
+declare_hw_range_handler(minio, 0, INT_MAX)
|
|
|
adddbf |
declare_hw_snprint(minio, print_nonzero)
|
|
|
adddbf |
-declare_mp_handler(minio, set_int)
|
|
|
adddbf |
+declare_mp_range_handler(minio, 0, INT_MAX)
|
|
|
adddbf |
declare_mp_snprint(minio, print_nonzero)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(minio_rq, set_int)
|
|
|
adddbf |
+declare_def_range_handler(minio_rq, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint_defint(minio_rq, print_int, DEFAULT_MINIO_RQ)
|
|
|
adddbf |
-declare_ovr_handler(minio_rq, set_int)
|
|
|
adddbf |
+declare_ovr_range_handler(minio_rq, 0, INT_MAX)
|
|
|
adddbf |
declare_ovr_snprint(minio_rq, print_nonzero)
|
|
|
adddbf |
-declare_hw_handler(minio_rq, set_int)
|
|
|
adddbf |
+declare_hw_range_handler(minio_rq, 0, INT_MAX)
|
|
|
adddbf |
declare_hw_snprint(minio_rq, print_nonzero)
|
|
|
adddbf |
-declare_mp_handler(minio_rq, set_int)
|
|
|
adddbf |
+declare_mp_range_handler(minio_rq, 0, INT_MAX)
|
|
|
adddbf |
declare_mp_snprint(minio_rq, print_nonzero)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(queue_without_daemon, set_yes_no)
|
|
|
adddbf |
@@ -562,7 +611,7 @@ snprint_def_queue_without_daemon (struct config *conf,
|
|
|
adddbf |
return 0;
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(checker_timeout, set_int)
|
|
|
adddbf |
+declare_def_range_handler(checker_timeout, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(checker_timeout, print_nonzero)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(flush_on_last_del, set_yes_no_undef)
|
|
|
adddbf |
@@ -630,13 +679,13 @@ declare_hw_snprint(deferred_remove, print_yes_no_undef)
|
|
|
adddbf |
declare_mp_handler(deferred_remove, set_yes_no_undef)
|
|
|
adddbf |
declare_mp_snprint(deferred_remove, print_yes_no_undef)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(retrigger_tries, set_int)
|
|
|
adddbf |
+declare_def_range_handler(retrigger_tries, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(retrigger_tries, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(retrigger_delay, set_int)
|
|
|
adddbf |
+declare_def_range_handler(retrigger_delay, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(retrigger_delay, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(uev_wait_timeout, set_int)
|
|
|
adddbf |
+declare_def_range_handler(uev_wait_timeout, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(uev_wait_timeout, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
declare_def_handler(strict_timing, set_yes_no)
|
|
|
adddbf |
@@ -662,19 +711,19 @@ static int snprint_def_disable_changed_wwids(struct config *conf, char *buff,
|
|
|
adddbf |
return print_ignored(buff, len);
|
|
|
adddbf |
}
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(remove_retries, set_int)
|
|
|
adddbf |
+declare_def_range_handler(remove_retries, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(remove_retries, print_int)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(max_sectors_kb, set_int)
|
|
|
adddbf |
+declare_def_range_handler(max_sectors_kb, 0, INT_MAX)
|
|
|
adddbf |
declare_def_snprint(max_sectors_kb, print_nonzero)
|
|
|
adddbf |
-declare_ovr_handler(max_sectors_kb, set_int)
|
|
|
adddbf |
+declare_ovr_range_handler(max_sectors_kb, 0, INT_MAX)
|
|
|
adddbf |
declare_ovr_snprint(max_sectors_kb, print_nonzero)
|
|
|
adddbf |
-declare_hw_handler(max_sectors_kb, set_int)
|
|
|
adddbf |
+declare_hw_range_handler(max_sectors_kb, 0, INT_MAX)
|
|
|
adddbf |
declare_hw_snprint(max_sectors_kb, print_nonzero)
|
|
|
adddbf |
-declare_mp_handler(max_sectors_kb, set_int)
|
|
|
adddbf |
+declare_mp_range_handler(max_sectors_kb, 0, INT_MAX)
|
|
|
adddbf |
declare_mp_snprint(max_sectors_kb, print_nonzero)
|
|
|
adddbf |
|
|
|
adddbf |
-declare_def_handler(find_multipaths_timeout, set_int)
|
|
|
adddbf |
+declare_def_range_handler(find_multipaths_timeout, INT_MIN, INT_MAX)
|
|
|
adddbf |
declare_def_snprint_defint(find_multipaths_timeout, print_int,
|
|
|
adddbf |
DEFAULT_FIND_MULTIPATHS_TIMEOUT)
|
|
|
adddbf |
|
|
|
adddbf |
@@ -1437,27 +1486,7 @@ declare_ovr_snprint(recheck_wwid, print_yes_no_undef)
|
|
|
adddbf |
declare_hw_handler(recheck_wwid, set_yes_no_undef)
|
|
|
adddbf |
declare_hw_snprint(recheck_wwid, print_yes_no_undef)
|
|
|
adddbf |
|
|
|
adddbf |
-
|
|
|
adddbf |
-static int
|
|
|
adddbf |
-def_uxsock_timeout_handler(struct config *conf, vector strvec, const char *file,
|
|
|
adddbf |
- int line_nr)
|
|
|
adddbf |
-{
|
|
|
adddbf |
- unsigned int uxsock_timeout;
|
|
|
adddbf |
- char *buff;
|
|
|
adddbf |
-
|
|
|
adddbf |
- buff = set_value(strvec);
|
|
|
adddbf |
- if (!buff)
|
|
|
adddbf |
- return 1;
|
|
|
adddbf |
-
|
|
|
adddbf |
- if (sscanf(buff, "%u", &uxsock_timeout) == 1 &&
|
|
|
adddbf |
- uxsock_timeout > DEFAULT_REPLY_TIMEOUT)
|
|
|
adddbf |
- conf->uxsock_timeout = uxsock_timeout;
|
|
|
adddbf |
- else
|
|
|
adddbf |
- conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
|
|
|
adddbf |
-
|
|
|
adddbf |
- free(buff);
|
|
|
adddbf |
- return 0;
|
|
|
adddbf |
-}
|
|
|
adddbf |
+declare_def_range_handler(uxsock_timeout, DEFAULT_REPLY_TIMEOUT, INT_MAX)
|
|
|
adddbf |
|
|
|
adddbf |
static int
|
|
|
adddbf |
hw_vpd_vendor_handler(struct config *conf, vector strvec, const char *file,
|