This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 0d50a658f5 [fix](config) Fix uninitialized config validator (#11022) 0d50a658f5 is described below commit 0d50a658f599e527b13350fa9527c6116d55ed0a Author: Compilation Success <106100979+compilethewo...@users.noreply.github.com> AuthorDate: Mon Jul 25 15:10:55 2022 +0800 [fix](config) Fix uninitialized config validator (#11022) * [fix](config) Fix uninitialized config validator If we don't set any validator, the original implementation will cause seg-fault due to nullptr of `RegisterConfValidator::_s_field_validator`, which initial value relies on the first config validator definition. We need to skip finding validator from uninitialized `RegisterConfValidator::_s_field_validator`. --- be/src/common/configbase.cpp | 67 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/be/src/common/configbase.cpp b/be/src/common/configbase.cpp index 35d89a69e4..e06988265f 100644 --- a/be/src/common/configbase.cpp +++ b/be/src/common/configbase.cpp @@ -311,13 +311,15 @@ std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) { TYPE& ref_conf_value = *reinterpret_cast<TYPE*>((FIELD).storage); \ TYPE old_value = ref_conf_value; \ ref_conf_value = new_value; \ - auto validator = RegisterConfValidator::_s_field_validator->find((FIELD).name); \ - if (validator != RegisterConfValidator::_s_field_validator->end() && \ - !(validator->second)()) { \ - ref_conf_value = old_value; \ - std::cerr << "validate " << (FIELD).name << "=" << new_value << " failed" \ - << std::endl; \ - return false; \ + if (RegisterConfValidator::_s_field_validator != nullptr) { \ + auto validator = RegisterConfValidator::_s_field_validator->find((FIELD).name); \ + if (validator != RegisterConfValidator::_s_field_validator->end() && \ + !(validator->second)()) { \ + ref_conf_value = old_value; \ + std::cerr << "validate " << (FIELD).name << "=" << new_value << " failed" \ + << std::endl; \ + return false; \ + } \ } \ if (FILL_CONF_MAP) { \ std::ostringstream oss; \ @@ -358,31 +360,32 @@ bool init(const char* conf_file, bool fill_conf_map, bool must_exist, bool set_t return true; } -#define UPDATE_FIELD(FIELD, VALUE, TYPE, PERSIST) \ - if (strcmp((FIELD).type, #TYPE) == 0) { \ - TYPE new_value; \ - if (!convert((VALUE), new_value)) { \ - return Status::InvalidArgument("convert '{}' as {} failed", VALUE, #TYPE); \ - } \ - TYPE& ref_conf_value = *reinterpret_cast<TYPE*>((FIELD).storage); \ - TYPE old_value = ref_conf_value; \ - ref_conf_value = new_value; \ - auto validator = RegisterConfValidator::_s_field_validator->find((FIELD).name); \ - if (validator != RegisterConfValidator::_s_field_validator->end() && \ - !(validator->second)()) { \ - ref_conf_value = old_value; \ - return Status::InvalidArgument("validate {}={} failed", (FIELD).name, new_value); \ - } \ - ref_conf_value = new_value; \ - if (full_conf_map != nullptr) { \ - std::ostringstream oss; \ - oss << new_value; \ - (*full_conf_map)[(FIELD).name] = oss.str(); \ - } \ - if (PERSIST) { \ - persist_config(std::string((FIELD).name), VALUE); \ - } \ - return Status::OK(); \ +#define UPDATE_FIELD(FIELD, VALUE, TYPE, PERSIST) \ + if (strcmp((FIELD).type, #TYPE) == 0) { \ + TYPE new_value; \ + if (!convert((VALUE), new_value)) { \ + return Status::InvalidArgument("convert '{}' as {} failed", VALUE, #TYPE); \ + } \ + TYPE& ref_conf_value = *reinterpret_cast<TYPE*>((FIELD).storage); \ + TYPE old_value = ref_conf_value; \ + if (RegisterConfValidator::_s_field_validator != nullptr) { \ + auto validator = RegisterConfValidator::_s_field_validator->find((FIELD).name); \ + if (validator != RegisterConfValidator::_s_field_validator->end() && \ + !(validator->second)()) { \ + ref_conf_value = old_value; \ + return Status::InvalidArgument("validate {}={} failed", (FIELD).name, new_value); \ + } \ + } \ + ref_conf_value = new_value; \ + if (full_conf_map != nullptr) { \ + std::ostringstream oss; \ + oss << new_value; \ + (*full_conf_map)[(FIELD).name] = oss.str(); \ + } \ + if (PERSIST) { \ + persist_config(std::string((FIELD).name), VALUE); \ + } \ + return Status::OK(); \ } // write config to be_custom.conf --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org