From: Kefu Chai Date: Sat, 30 Apr 2016 10:31:37 +0000 (+0800) Subject: common/config: cast OPT_U32 options using uint32_t X-Git-Tag: v10.2.4~76^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f7cd28460147530cfd265a593b32d02adb93abe6;p=ceph.git common/config: cast OPT_U32 options using uint32_t the OPT_U32 options was translated using strict_si_cast(), and then cast the converted result to uint32_t. this could cause integer underflow. we could have lifted the burden of checking invalid input from the user of this option to the strict_si_cast<>() function. so in this change, we use strict_si_cast() instead, before casting the converted value into `uint32_t`. Signed-off-by: Kefu Chai (cherry picked from commit b7babd6aa671d688eef0af61ca17fd11eec22773) --- diff --git a/src/common/config.cc b/src/common/config.cc index 622e23715c4a..d27bfbff5097 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -994,7 +994,7 @@ int md_config_t::set_val_raw(const char *val, const config_option *opt) return 0; case OPT_U32: { std::string err; - int f = strict_si_cast(val, &err); + int f = strict_si_cast(val, &err); if (!err.empty()) return -EINVAL; *(uint32_t*)opt->conf_ptr(this) = f; diff --git a/src/common/strtol.cc b/src/common/strtol.cc index 50598b9288e7..bc5ccc74cb11 100644 --- a/src/common/strtol.cc +++ b/src/common/strtol.cc @@ -186,10 +186,9 @@ T strict_si_cast(const char *str, std::string *err) } template int strict_si_cast(const char *str, std::string *err); - template long long strict_si_cast(const char *str, std::string *err); - template uint64_t strict_si_cast(const char *str, std::string *err); +template uint32_t strict_si_cast(const char *str, std::string *err); uint64_t strict_sistrtoll(const char *str, std::string *err) {