Skip to content

Commit

Permalink
Do not allow 1 as installonly_limit value (RhBug:1926261)
Browse files Browse the repository at this point in the history
Value 1 is confusing for users and should not be allowed as
installonly_limit value.
Also handling of negative values is fixed - std::stoul() does not fail
on negative input in the string.

= changelog =
msg:           do not allow 1 as installonly_limit value
type:          enhancement
resolves:      https://bugzilla.redhat.com/show_bug.cgi?id=1926261
  • Loading branch information
m-blaha authored and pkratoch committed Apr 6, 2021
1 parent 31a8b8b commit a6e943b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libdnf/conf/ConfigMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,18 @@ class ConfigMain::Impl {
[](const std::string & value)->std::uint32_t{
if (value == "<off>")
return 0;
std::int32_t value_i;
try {
return std::stoul(value);
value_i = std::stol(value);
}
catch (...) {
return 0;
throw Option::InvalidValue(tfm::format(_("invalid value")));
}
if (value_i == 1)
throw Option::InvalidValue(tfm::format(_("value 1 is not allowed")));
if (value_i < 0)
throw Option::InvalidValue(tfm::format(_("negative value is not allowed")));
return (std::uint32_t)value_i;
}
};

Expand Down

0 comments on commit a6e943b

Please sign in to comment.