]> 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)
committerKefu Chai <kchai@redhat.com>
Tue, 17 May 2016 05:41:50 +0000 (13:41 +0800)
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>
src/common/config.cc
src/common/strtol.cc

index 47c01797dc1aaa16ceddc18a6b8b2467184fd3d2..ddbb2d0f32d3c9d1364f9ccfb025a2863b8abfb3 100644 (file)
@@ -998,7 +998,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)
 {