From e0812957d606ddbde9db9df6cb468eb4ad689320 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 19 Mar 2024 08:11:38 +0200 Subject: Validate ram-{minimum,maximum} in machine header manifest are not zero --- libbbot/manifest.cxx | 16 ++++++++++++---- libbbot/manifest.hxx | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/libbbot/manifest.cxx b/libbbot/manifest.cxx index ab392e4..45a4668 100644 --- a/libbbot/manifest.cxx +++ b/libbbot/manifest.cxx @@ -276,8 +276,9 @@ namespace bbot ram_minimum = parse_uint64 (v); - if (!ram_minimum) - bad_value ("machine minimum RAM should be 64-bit unsigned integer"); + if (!ram_minimum || *ram_minimum == 0) + bad_value ( + "machine minimum RAM should be non-zero 64-bit unsigned integer"); } else if (n == "ram-maximum") { @@ -286,8 +287,9 @@ namespace bbot ram_maximum = parse_uint64 (v); - if (!ram_maximum) - bad_value ("machine maximum RAM should be 64-bit unsigned integer"); + if (!ram_maximum || *ram_maximum == 0) + bad_value ( + "machine maximum RAM should be non-zero 64-bit unsigned integer"); } else { @@ -333,10 +335,16 @@ namespace bbot s.next ("role", to_string (*role)); if (ram_minimum) + { + assert (*ram_minimum != 0); s.next ("ram-minimum", std::to_string (*ram_minimum)); + } if (ram_maximum) + { + assert (*ram_maximum != 0); s.next ("ram-maximum", std::to_string (*ram_maximum)); + } if (end_of_manifest) s.next ("", ""); // End of manifest. diff --git a/libbbot/manifest.hxx b/libbbot/manifest.hxx index a815d3e..909d47d 100644 --- a/libbbot/manifest.hxx +++ b/libbbot/manifest.hxx @@ -52,8 +52,8 @@ namespace bbot std::string name; std::string summary; butl::optional role; - butl::optional ram_minimum; // In KiB. - butl::optional ram_maximum; // In KiB. + butl::optional ram_minimum; // In KiB, non-zero. + butl::optional ram_maximum; // In KiB, non-zero. // Return the effective machine role. If the role is not explicitly // specified, then the build role is assumed. -- cgit v1.1