From 290dcff48e32c16abc4711bc52432fe8a9e09b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 9 Aug 2018 14:24:54 +0300 Subject: [PATCH] Add runtime size type check Took the size type validity check function into use in runtime configuration. This fixes the problem with zero not being accepted as a valid size for query_classifier_cache_size. --- server/core/config_runtime.cc | 51 ++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index bb87ac23f..0e73818f3 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -781,17 +781,26 @@ bool runtime_alter_maxscale(const char* name, const char* value) } else if (key == CN_QUERY_CLASSIFIER_CACHE_SIZE) { - char* end; - long max_size = strtol(value, &end, 10); + uint64_t max_size; - if ((max_size >= 0) && (*end == 0)) + if (get_suffixed_size(value, &max_size)) { - MXS_NOTICE("Updated '%s' from %" PRIi64 " to %ld", - CN_QUERY_CLASSIFIER_CACHE_SIZE, cnf.qc_cache_properties.max_size, max_size); + decltype(QC_CACHE_PROPERTIES::max_size) new_size = max_size; - cnf.qc_cache_properties.max_size = max_size; - qc_set_cache_properties(&cnf.qc_cache_properties); - rval = true; + if (new_size >= 0) + { + MXS_NOTICE("Updated '%s' from %" PRIi64 " to %lu", + CN_QUERY_CLASSIFIER_CACHE_SIZE, + cnf.qc_cache_properties.max_size, max_size); + + cnf.qc_cache_properties.max_size = new_size; + qc_set_cache_properties(&cnf.qc_cache_properties); + rval = true; + } + else + { + config_runtime_error("Value too large for '%s': %s", CN_QUERY_CLASSIFIER_CACHE_SIZE, value); + } } else { @@ -1319,6 +1328,30 @@ bool runtime_is_bool_or_null(json_t* json, const char* path) return rval; } +bool runtime_is_size_or_null(json_t* json, const char* path) +{ + bool rval = true; + json_t* value = mxs_json_pointer(json, path); + + if (value) + { + if (!json_is_integer(value) && !json_is_string(value)) + { + config_runtime_error("Parameter '%s' is not an integer or a string but %s", + path, json_type_to_string(value)); + rval = false; + } + else if ((json_is_integer(value) && json_integer_value(value) < 0) || + (json_is_string(value) && !get_suffixed_size(json_string_value(value), nullptr))) + { + config_runtime_error("Parameter '%s' is not a valid size", path); + rval = false; + } + } + + return rval; +} + bool runtime_is_count_or_null(json_t* json, const char* path) { bool rval = true; @@ -2499,7 +2532,7 @@ bool validate_maxscale_json(json_t* json) runtime_is_count_or_null(param, CN_AUTH_WRITE_TIMEOUT) && runtime_is_bool_or_null(param, CN_ADMIN_AUTH) && runtime_is_bool_or_null(param, CN_ADMIN_LOG_AUTH_FAILURES) && - runtime_is_count_or_null(param, CN_QUERY_CLASSIFIER_CACHE_SIZE); + runtime_is_size_or_null(param, CN_QUERY_CLASSIFIER_CACHE_SIZE); } return rval;