Fix the String type of pendingAttributes method

When the user calls the `pendingAttributes` method, if the
`attributeType` is equal to the string type, there is a chance that
the previous logic will fail because of the `std::get<1>` exception.

Since the string type has joined `MinStringLength` and
`MaxStringLength`, it is necessary to verify the maximum length and
minimum length of the string.

resolved: https://github.com/openbmc/bios-settings-mgr/issues/2

Tested:
If the length of the hb_lid_ids attribute value we configure is 0 to
10, which is when we set a string with a length of more than 10
bytes, an exception will be thrown.

bios/string_attrs.json:
{
 "attribute_name" : "hb_lid_ids",
 "string_type" : "ASCII",
 "minimum_string_length" : 0,
 "maximum_string_length" : 10,
 "default_string_length" : 0,
 "default_string" : "",
 "helpText" : "Provides the host a mapping of the lid IDs to human
              readable names.",
 "displayName" : "Hostboot Lid IDs"
}

busctl call xyz.openbmc_project.BIOSConfigManager
/xyz/openbmc_project/bios_config/manager
org.freedesktop.DBus.Properties Set ssv
xyz.openbmc_project.BIOSConfig.Manager PendingAttributes a{s\(sv\)} 1
"hb_lid_ids"
"xyz.openbmc_project.BIOSConfig.Manager.AttributeType.String" s
"123456789023"
Call failed: Invalid argument was given.

journalctl -o json-pretty SYSLOG_IDENTIFIER=biosconfig-manager
{
 "_SYSTEMD_INVOCATION_ID" : "0930e3a7967e4eb68429fd472afebcec",
 "_HOSTNAME" : "fp5280g2",
 "_PID" : "243",
 "ATTRVALUE" : "123456789023",
 "_EXE" : "/usr/bin/biosconfig-manager",
 "_CMDLINE" : "/usr/bin/biosconfig-manager",
 "_SYSTEMD_SLICE" : "system.slice",
 "SYSLOG_IDENTIFIER" : "biosconfig-manager",
 "__REALTIME_TIMESTAMP" : "305445800",
 "_GID" : "0",
 "MINLEN" : "0",
 "MAXLEN" : "10",
 "CODE_LINE" : "210",
 "MESSAGE" : "123456789023 Length is out of range, bound is invalid,
              maxStringLength = 10, minStringLength = 0",
 ...
}

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ic13a8acf8417beb92ea3ed1bec5a4bc58d3adda9
diff --git a/src/manager.cpp b/src/manager.cpp
index 0cb4259..89727e6 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -180,20 +180,34 @@
             const auto& options =
                 std::get<static_cast<uint8_t>(Index::options)>(iter->second);
 
-            auto optionsIterator = options.begin();
-
-            for (; optionsIterator != options.end(); ++optionsIterator)
+            size_t minStringLength = 0;
+            size_t maxStringLength = 0;
+            for (const auto& stringOptions : options)
             {
-                if (std::get<1>(std::get<1>(*optionsIterator)) == attrValue)
+                if (BoundType::MinStringLength == std::get<0>(stringOptions))
                 {
-                    break;
+                    minStringLength =
+                        std::get<int64_t>(std::get<1>(stringOptions));
+                }
+                else if (BoundType::MaxStringLength ==
+                         std::get<0>(stringOptions))
+                {
+                    maxStringLength =
+                        std::get<int64_t>(std::get<1>(stringOptions));
+                }
+                else
+                {
+                    continue;
                 }
             }
 
-            if (optionsIterator == options.end())
+            if (attrValue.length() < minStringLength ||
+                attrValue.length() > maxStringLength)
             {
-                lg2::error("{ATTRVALUE} is not a valid value for {NAME}",
-                           "ATTRVALUE", attrValue, "NAME", pair.first);
+                lg2::error(
+                    "{ATTRVALUE} Length is out of range, bound is invalid, maxStringLength = {MAXLEN}, minStringLength = {MINLEN}",
+                    "ATTRVALUE", attrValue, "MAXLEN", maxStringLength, "MINLEN",
+                    minStringLength);
                 throw InvalidArgument();
             }
         }