Commit 7c5306a8 authored by Max Kellermann's avatar Max Kellermann

config/{Block,Global}: add missing strtoul() check

parent 201210cf
......@@ -31,9 +31,10 @@
int
BlockParam::GetIntValue() const
{
const char *const s = value.c_str();
char *endptr;
long value2 = strtol(value.c_str(), &endptr, 0);
if (*endptr != 0)
long value2 = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", line);
return value2;
......@@ -42,9 +43,10 @@ BlockParam::GetIntValue() const
unsigned
BlockParam::GetUnsignedValue() const
{
const char *const s = value.c_str();
char *endptr;
unsigned long value2 = strtoul(value.c_str(), &endptr, 0);
if (*endptr != 0)
unsigned long value2 = strtoul(s, &endptr, 0);
if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", line);
return (unsigned)value2;
......
......@@ -140,8 +140,9 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
if (param == nullptr)
return default_value;
value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0 || value < 0)
const char *const s = param->value.c_str();
value = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0 || value < 0)
FormatFatalError("Not a valid non-negative number in line %i",
param->line);
......@@ -158,8 +159,9 @@ config_get_positive(ConfigOption option, unsigned default_value)
if (param == nullptr)
return default_value;
value = strtol(param->value.c_str(), &endptr, 0);
if (*endptr != 0)
const char *const s = param->value.c_str();
value = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", param->line);
if (value <= 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment