From a6e943bee19e769447c8dd910bf9bf70992b12a8 Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Fri, 5 Mar 2021 15:43:44 +0100 Subject: [PATCH] Do not allow 1 as installonly_limit value (RhBug:1926261) 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 --- libdnf/conf/ConfigMain.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libdnf/conf/ConfigMain.cpp b/libdnf/conf/ConfigMain.cpp index 39ed4b1e15..37d9ca0d12 100644 --- a/libdnf/conf/ConfigMain.cpp +++ b/libdnf/conf/ConfigMain.cpp @@ -196,12 +196,18 @@ class ConfigMain::Impl { [](const std::string & value)->std::uint32_t{ if (value == "") 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; } };