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

This commit is contained in:
Max Kellermann 2018-01-02 17:23:10 +01:00
parent 201210cfe1
commit 7c5306a841
2 changed files with 12 additions and 8 deletions

View File

@ -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
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;

View File

@ -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)
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)