From: Hans de Goede Date: Mon, 17 Feb 2025 15:05:54 +0000 (+0100) Subject: ply-keyfile: Change ply_key_file_get_long () into ply_key_file_get_ulong () X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf80db4ec319d2f64071aa1f750e23d40b5d5fc5;p=thirdparty%2Fplymouth.git ply-keyfile: Change ply_key_file_get_long () into ply_key_file_get_ulong () 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 --- diff --git a/src/libply/ply-key-file.c b/src/libply/ply-key-file.c index 28a4885c..c296865a 100644 --- a/src/libply/ply-key-file.c +++ b/src/libply/ply-key-file.c @@ -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 diff --git a/src/libply/ply-key-file.h b/src/libply/ply-key-file.h index e240363c..487fd137 100644 --- a/src/libply/ply-key-file.h +++ b/src/libply/ply-key-file.h @@ -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); diff --git a/src/plugins/splash/fade-throbber/plugin.c b/src/plugins/splash/fade-throbber/plugin.c index 17c4e25a..d9e018f5 100644 --- a/src/plugins/splash/fade-throbber/plugin.c +++ b/src/plugins/splash/fade-throbber/plugin.c @@ -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; diff --git a/src/plugins/splash/script/plugin.c b/src/plugins/splash/script/plugin.c index 0bdd0258..a2e7443a 100644 --- a/src/plugins/splash/script/plugin.c +++ b/src/plugins/splash/script/plugin.c @@ -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 (); diff --git a/src/plugins/splash/space-flares/plugin.c b/src/plugins/splash/space-flares/plugin.c index e7ab76d5..8161dfa7 100644 --- a/src/plugins/splash/space-flares/plugin.c +++ b/src/plugins/splash/space-flares/plugin.c @@ -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; diff --git a/src/plugins/splash/two-step/plugin.c b/src/plugins/splash/two-step/plugin.c index 8fa0d621..65789bed 100644 --- a/src/plugins/splash/two-step/plugin.c +++ b/src/plugins/splash/two-step/plugin.c @@ -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);