From f7cd28460147530cfd265a593b32d02adb93abe6 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 30 Apr 2016 18:31:37 +0800 Subject: [PATCH] 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) --- src/common/config.cc | 2 +- src/common/strtol.cc | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/common/config.cc b/src/common/config.cc index 622e23715c4a4..d27bfbff50972 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 50598b9288e7a..bc5ccc74cb115 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) { -- 2.39.5