case OPT_STR:
*(std::string*)opt->conf_ptr(this) = val ? val : "";
return 0;
- case OPT_FLOAT:
- *(float*)opt->conf_ptr(this) = atof(val);
+ case OPT_FLOAT: {
+ std::string err;
+ float f = strict_strtof(val, &err);
+ if (!err.empty())
+ return -EINVAL;
+ *(float*)opt->conf_ptr(this) = f;
return 0;
- case OPT_DOUBLE:
- *(double*)opt->conf_ptr(this) = atof(val);
+ }
+ case OPT_DOUBLE: {
+ std::string err;
+ double f = strict_strtod(val, &err);
+ if (!err.empty())
+ return -EINVAL;
+ *(double*)opt->conf_ptr(this) = f;
return 0;
+ }
case OPT_BOOL:
if (strcasecmp(val, "false") == 0)
*(bool*)opt->conf_ptr(this) = false;
}
}
+TEST(DaemonConfig, InvalidFloats) {
+ {
+ double bad_value = 2 * (double)std::numeric_limits<float>::max();
+ string str = boost::lexical_cast<string>(-bad_value);
+ int ret = g_ceph_context->_conf->set_val("log_stop_at_utilization", str);
+ ASSERT_EQ(ret, -EINVAL);
+ }
+ {
+ double bad_value = 2 * (double)std::numeric_limits<float>::max();
+ string str = boost::lexical_cast<string>(bad_value);
+ int ret = g_ceph_context->_conf->set_val("log_stop_at_utilization", str);
+ ASSERT_EQ(ret, -EINVAL);
+ }
+ {
+ int ret = g_ceph_context->_conf->set_val("log_stop_at_utilization", "not a float");
+ ASSERT_EQ(ret, -EINVAL);
+ }
+}
+
/*
* Local Variables:
* compile-command: "cd .. ; make unittest_daemon_config && ./unittest_daemon_config"