the OPT_U32 options was translated using strict_si_cast<int>(), 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<uint32_t>() instead, before casting
the converted value into `uint32_t`.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
(cherry picked from commit
b7babd6aa671d688eef0af61ca17fd11eec22773)
return 0;
case OPT_U32: {
std::string err;
- int f = strict_si_cast<int>(val, &err);
+ int f = strict_si_cast<uint32_t>(val, &err);
if (!err.empty())
return -EINVAL;
*(uint32_t*)opt->conf_ptr(this) = f;
}
template int strict_si_cast<int>(const char *str, std::string *err);
-
template long long strict_si_cast<long long>(const char *str, std::string *err);
-
template uint64_t strict_si_cast<uint64_t>(const char *str, std::string *err);
+template uint32_t strict_si_cast<uint32_t>(const char *str, std::string *err);
uint64_t strict_sistrtoll(const char *str, std::string *err)
{