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

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

parent 201210cf
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
int int
BlockParam::GetIntValue() const BlockParam::GetIntValue() const
{ {
const char *const s = value.c_str();
char *endptr; char *endptr;
long value2 = strtol(value.c_str(), &endptr, 0); long value2 = strtol(s, &endptr, 0);
if (*endptr != 0) if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", line); FormatFatalError("Not a valid number in line %i", line);
return value2; return value2;
...@@ -42,9 +43,10 @@ BlockParam::GetIntValue() const ...@@ -42,9 +43,10 @@ BlockParam::GetIntValue() const
unsigned unsigned
BlockParam::GetUnsignedValue() const BlockParam::GetUnsignedValue() const
{ {
const char *const s = value.c_str();
char *endptr; char *endptr;
unsigned long value2 = strtoul(value.c_str(), &endptr, 0); unsigned long value2 = strtoul(s, &endptr, 0);
if (*endptr != 0) if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", line); FormatFatalError("Not a valid number in line %i", line);
return (unsigned)value2; return (unsigned)value2;
......
...@@ -140,8 +140,9 @@ config_get_unsigned(ConfigOption option, unsigned default_value) ...@@ -140,8 +140,9 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
value = strtol(param->value.c_str(), &endptr, 0); const char *const s = param->value.c_str();
if (*endptr != 0 || value < 0) value = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0 || value < 0)
FormatFatalError("Not a valid non-negative number in line %i", FormatFatalError("Not a valid non-negative number in line %i",
param->line); param->line);
...@@ -158,8 +159,9 @@ config_get_positive(ConfigOption option, unsigned default_value) ...@@ -158,8 +159,9 @@ config_get_positive(ConfigOption option, unsigned default_value)
if (param == nullptr) if (param == nullptr)
return default_value; return default_value;
value = strtol(param->value.c_str(), &endptr, 0); const char *const s = param->value.c_str();
if (*endptr != 0) value = strtol(s, &endptr, 0);
if (endptr == s || *endptr != 0)
FormatFatalError("Not a valid number in line %i", param->line); FormatFatalError("Not a valid number in line %i", param->line);
if (value <= 0) 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