]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-keyfile: Change ply_key_file_get_long () into ply_key_file_get_ulong ()
authorHans de Goede <hdegoede@redhat.com>
Mon, 17 Feb 2025 15:05:54 +0000 (16:05 +0100)
committerHans de Goede <hdegoede@redhat.com>
Tue, 4 Mar 2025 11:35:05 +0000 (12:35 +0100)
Change ply_key_file_get_long () into ply_key_file_get_ulong () and add
error checking.

All callers of ply_key_file_get_long () expect a positive / unsigned number.
Rename it to ply_key_file_get_ulong ().

Also add error checkig for non valid numbers and return the default value
for these instead of 0.

Note this also fixes the return value of ply_key_file_get_long () being
a double (this is now changed to an unsigned long).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
src/libply/ply-key-file.c
src/libply/ply-key-file.h
src/plugins/splash/fade-throbber/plugin.c
src/plugins/splash/script/plugin.c
src/plugins/splash/space-flares/plugin.c
src/plugins/splash/two-step/plugin.c

index 28a4885cb2a962eb3918d98b2ebac77c67bb1cf6..c296865ad003ce7151c75bbcf6ffb5ab521575cb 100644 (file)
@@ -406,18 +406,27 @@ ply_key_file_get_double (ply_key_file_t *key_file,
         return ply_strtod (raw_value);
 }
 
-double
-ply_key_file_get_long (ply_key_file_t *key_file,
-                       const char     *group,
-                       const char     *key,
-                       long            default_value)
+unsigned long
+ply_key_file_get_ulong (ply_key_file_t *key_file,
+                        const char     *group,
+                        const char     *key,
+                        unsigned long   default_value)
 {
         char *raw_value = ply_key_file_get_raw_value (key_file, group, key);
+        char *endptr = NULL;
+        unsigned long u;
 
         if (!raw_value)
                 return default_value;
 
-        return strtol (raw_value, NULL, 0);
+        u = strtoul (raw_value, &endptr, 0);
+        if (*endptr != '\0') {
+                ply_trace ("group '%s' key '%s' val '%s' is not a valid unsigned number",
+                           group, key, raw_value);
+                return default_value;
+        }
+
+        return u;
 }
 
 static void
index e240363c13040ac9769b4d2671d784c1b773c08d..487fd137eeb29af9af50da5523237659d8197033 100644 (file)
@@ -55,10 +55,10 @@ double ply_key_file_get_double (ply_key_file_t *key_file,
                                 const char     *group_name,
                                 const char     *key,
                                 double          default_value);
-double ply_key_file_get_long (ply_key_file_t *key_file,
-                              const char     *group,
-                              const char     *key,
-                              long            default_value);
+unsigned long ply_key_file_get_ulong (ply_key_file_t *key_file,
+                                      const char     *group,
+                                      const char     *key,
+                                      unsigned long   default_value);
 void ply_key_file_foreach_entry (ply_key_file_t             *key_file,
                                  ply_key_file_foreach_func_t func,
                                  void                       *user_data);
index 17c4e25a353b189ccda26e7acca629c3f5890ac1..d9e018f527495a77faecd4ec4d3ff49242e1016b 100644 (file)
@@ -255,14 +255,14 @@ create_plugin (ply_key_file_t *key_file)
                 plugin->monospace_font = strdup ("monospace 10");
 
         plugin->console_text_color =
-                ply_key_file_get_long (key_file, "fade-throbber",
-                                       "ConsoleLogTextColor",
-                                       PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
+                ply_key_file_get_ulong (key_file, "fade-throbber",
+                                        "ConsoleLogTextColor",
+                                        PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
 
         plugin->console_background_color =
-                ply_key_file_get_long (key_file, "fade-throbber",
-                                       "ConsoleLogBackgroundColor",
-                                       0x00000000);
+                ply_key_file_get_ulong (key_file, "fade-throbber",
+                                        "ConsoleLogBackgroundColor",
+                                        0x00000000);
 
         plugin->image_dir = image_dir;
 
index 0bdd0258fa20df8e11e000575513249409ed3f29..a2e7443a1b4420c10445966ae1114ed779e04fe2 100644 (file)
@@ -233,14 +233,14 @@ create_plugin (ply_key_file_t *key_file)
                 plugin->monospace_font = strdup ("monospace 10");
 
         plugin->console_text_color =
-                ply_key_file_get_long (key_file, "script",
-                                       "ConsoleLogTextColor",
-                                       PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
+                ply_key_file_get_ulong (key_file, "script",
+                                        "ConsoleLogTextColor",
+                                        PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
 
         plugin->console_background_color =
-                ply_key_file_get_long (key_file, "script",
-                                       "ConsoleLogBackgroundColor",
-                                       0x00000000);
+                ply_key_file_get_ulong (key_file, "script",
+                                        "ConsoleLogBackgroundColor",
+                                        0x00000000);
 
         plugin->displays = ply_list_new ();
 
index e7ab76d5387de05e4d28cb94f0e2f480a5b44a27..8161dfa7f0a8b9e949603c0ec664b6c98dfaba3f 100644 (file)
@@ -634,14 +634,14 @@ create_plugin (ply_key_file_t *key_file)
                 plugin->monospace_font = strdup ("monospace 10");
 
         plugin->console_text_color =
-                ply_key_file_get_long (key_file, "space-flares",
-                                       "ConsoleLogTextColor",
-                                       PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
+                ply_key_file_get_ulong (key_file, "space-flares",
+                                        "ConsoleLogTextColor",
+                                        PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
 
         plugin->console_background_color =
-                ply_key_file_get_long (key_file, "space-flares",
-                                       "ConsoleLogBackgroundColor",
-                                       0x00000000);
+                ply_key_file_get_ulong (key_file, "space-flares",
+                                        "ConsoleLogBackgroundColor",
+                                        0x00000000);
 
         plugin->state = PLY_BOOT_SPLASH_DISPLAY_NORMAL;
         plugin->progress = 0;
index 8fa0d621e734ff3c61f2e26bc292f22fb50a8d5a..65789bed780da631bf1a309101cdf477f45a606d 100644 (file)
@@ -1286,44 +1286,44 @@ create_plugin (ply_key_file_t *key_file)
 
 
         plugin->console_text_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ConsoleLogTextColor",
-                                       PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ConsoleLogTextColor",
+                                        PLY_CONSOLE_VIEWER_LOG_TEXT_COLOR);
 
         plugin->console_background_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ConsoleLogBackgroundColor",
-                                       0x00000000);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ConsoleLogBackgroundColor",
+                                        0x00000000);
 
         plugin->transition_duration =
                 ply_key_file_get_double (key_file, "two-step",
                                          "TransitionDuration", 0.0);
 
         plugin->background_start_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "BackgroundStartColor",
-                                       PLYMOUTH_BACKGROUND_START_COLOR);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "BackgroundStartColor",
+                                        PLYMOUTH_BACKGROUND_START_COLOR);
         plugin->background_end_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "BackgroundEndColor",
-                                       PLYMOUTH_BACKGROUND_END_COLOR);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "BackgroundEndColor",
+                                        PLYMOUTH_BACKGROUND_END_COLOR);
 
         plugin->progress_bar_bg_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ProgressBarBackgroundColor",
-                                       0xffffff /* white */);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ProgressBarBackgroundColor",
+                                        0xffffff /* white */);
         plugin->progress_bar_fg_color =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ProgressBarForegroundColor",
-                                       0x000000 /* black */);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ProgressBarForegroundColor",
+                                        0x000000 /* black */);
         plugin->progress_bar_width =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ProgressBarWidth",
-                                       PROGRESS_BAR_WIDTH);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ProgressBarWidth",
+                                        PROGRESS_BAR_WIDTH);
         plugin->progress_bar_height =
-                ply_key_file_get_long (key_file, "two-step",
-                                       "ProgressBarHeight",
-                                       PROGRESS_BAR_HEIGHT);
+                ply_key_file_get_ulong (key_file, "two-step",
+                                        "ProgressBarHeight",
+                                        PROGRESS_BAR_HEIGHT);
 
         load_mode_settings (plugin, key_file, "boot-up", PLY_BOOT_SPLASH_MODE_BOOT_UP);
         load_mode_settings (plugin, key_file, "shutdown", PLY_BOOT_SPLASH_MODE_SHUTDOWN);