]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: cast OPT_U32 options using uint32_t
authorKefu Chai <tchaikov@gmail.com>
Sat, 30 Apr 2016 10:31:37 +0000 (18:31 +0800)
committerLoic Dachary <ldachary@redhat.com>
Thu, 25 Aug 2016 07:09:47 +0000 (09:09 +0200)
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)

src/common/config.cc
src/common/strtol.cc

index 622e23715c4a42ee5bac8e93bea841589214ee0a..d27bfbff50972fb31fde7c3bfe5596e81c323adf 100644 (file)
@@ -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<int>(val, &err);
+      int f = strict_si_cast<uint32_t>(val, &err);
       if (!err.empty())
        return -EINVAL;
       *(uint32_t*)opt->conf_ptr(this) = f;
index 50598b9288e7ab64ebf267ee26c0df62b5351975..bc5ccc74cb115a019af350eb2837b11205ffa95b 100644 (file)
@@ -186,10 +186,9 @@ T strict_si_cast(const char *str, std::string *err)
 }
 
 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)
 {