]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Drop use of Atoi
authorJan Janssen <medhefgo@web.de>
Wed, 1 Jun 2022 11:42:23 +0000 (13:42 +0200)
committerJan Janssen <medhefgo@web.de>
Fri, 10 Jun 2022 09:50:13 +0000 (11:50 +0200)
src/boot/efi/boot.c
src/boot/efi/util.c

index 3833ae9461c6960c4244bf98d8ac6c66b9da9a49..7d881fc75255b0799d68ec964cc57c3b528d1e12 100644 (file)
@@ -1159,10 +1159,12 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) {
                         else if (streq8((char *) value, "menu-hidden"))
                                 config->timeout_sec_config = TIMEOUT_MENU_HIDDEN;
                         else {
-                                _cleanup_freepool_ CHAR16 *s = NULL;
-
-                                s = xstra_to_str(value);
-                                config->timeout_sec_config = MIN(Atoi(s), TIMEOUT_TYPE_MAX);
+                                uint64_t u;
+                                if (!parse_number8((char *) value, &u, NULL) || u > TIMEOUT_TYPE_MAX) {
+                                        log_error_stall(L"Error parsing 'timeout' config option: %a", value);
+                                        continue;
+                                }
+                                config->timeout_sec_config = u;
                         }
                         config->timeout_sec = config->timeout_sec_config;
                         continue;
@@ -1221,10 +1223,12 @@ static void config_defaults_load_from_file(Config *config, CHAR8 *content) {
                         else if (streq8((char *) value, "keep"))
                                 config->console_mode = CONSOLE_MODE_KEEP;
                         else {
-                                _cleanup_freepool_ CHAR16 *s = NULL;
-
-                                s = xstra_to_str(value);
-                                config->console_mode = MIN(Atoi(s), (UINTN)CONSOLE_MODE_RANGE_MAX);
+                                uint64_t u;
+                                if (!parse_number8((char *) value, &u, NULL) || u > CONSOLE_MODE_RANGE_MAX) {
+                                        log_error_stall(L"Error parsing 'console-mode' config option: %a", value);
+                                        continue;
+                                }
+                                config->console_mode = u;
                         }
                         continue;
                 }
index c6324035ad59d7e1161329f7eeeaf815c848a31b..8ec7e17efc109bc5071a62719873e172b01317da 100644 (file)
@@ -127,16 +127,21 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value
 EFI_STATUS efivar_get_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN *i) {
         _cleanup_freepool_ CHAR16 *val = NULL;
         EFI_STATUS err;
+        uint64_t u;
 
         assert(vendor);
         assert(name);
         assert(i);
 
         err = efivar_get(vendor, name, &val);
-        if (!EFI_ERROR(err))
-                *i = Atoi(val);
+        if (err != EFI_SUCCESS)
+                return err;
 
-        return err;
+        if (!parse_number16(val, &u, NULL) || u > UINTN_MAX)
+                return EFI_INVALID_PARAMETER;
+
+        *i = u;
+        return EFI_SUCCESS;
 }
 
 EFI_STATUS efivar_get_uint32_le(const EFI_GUID *vendor, const CHAR16 *name, UINT32 *ret) {