From 4c8d04030c43c4c3fb84ef0962a40730e70b6deb Mon Sep 17 00:00:00 2001 From: hueso Date: Thu, 15 May 2025 11:59:21 -0300 Subject: [PATCH] Fixed buffer overflows in sunrise_sunset_face --- watch-faces/complication/sunrise_sunset_face.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/watch-faces/complication/sunrise_sunset_face.c b/watch-faces/complication/sunrise_sunset_face.c index 58514848..f5f5df2f 100644 --- a/watch-faces/complication/sunrise_sunset_face.c +++ b/watch-faces/complication/sunrise_sunset_face.c @@ -108,7 +108,7 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) { watch_clear_indicator(WATCH_INDICATOR_24H); if (result == 1) watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "SET", "SE"); else watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "RIS", "rI"); - sprintf(buf, "%2d", scratch_time.unit.day); + snprintf(buf, sizeof(buf), "%2d", scratch_time.unit.day); watch_display_text(WATCH_POSITION_TOP_RIGHT, buf); watch_display_text(WATCH_POSITION_BOTTOM, "None "); return; @@ -149,9 +149,9 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) { else watch_clear_indicator(WATCH_INDICATOR_PM); } watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "RIS", "rI"); - sprintf(buf, "%2d", scratch_time.unit.day); + snprintf(buf, sizeof(buf), "%2d", scratch_time.unit.day); watch_display_text(WATCH_POSITION_TOP_RIGHT, buf); - sprintf(buf, "%2d%02d%2s", scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); + snprintf(buf, sizeof(buf), "%2d%02d%2s", scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); watch_display_text(WATCH_POSITION_BOTTOM, buf); return; } else { @@ -188,9 +188,9 @@ static void _sunrise_sunset_face_update(sunrise_sunset_state_t *state) { else watch_clear_indicator(WATCH_INDICATOR_PM); } watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "SET", "SE"); - sprintf(buf, "%2d", scratch_time.unit.day); + snprintf(buf, sizeof(buf), "%2d", scratch_time.unit.day); watch_display_text(WATCH_POSITION_TOP_RIGHT, buf); - sprintf(buf, "%2d%02d%2s", scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); + snprintf(buf, sizeof(buf), "%2d%02d%2s", scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); watch_display_text(WATCH_POSITION_BOTTOM, buf); return; } else { @@ -274,7 +274,7 @@ static void _sunrise_sunset_face_update_settings_display(movement_event_t event, if (state->active_digit == 4) watch_display_character(' ', 9); } } else { - sprintf(buf, "%c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); + snprintf(buf, sizeof(buf), "%c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); if (event.subsecond % 2) buf[state->active_digit] = ' '; watch_display_text(WATCH_POSITION_BOTTOM, buf); } @@ -301,7 +301,7 @@ static void _sunrise_sunset_face_update_settings_display(movement_event_t event, if (state->active_digit == 4) watch_display_character(' ', 9); } } else { - sprintf(buf, "%c%05d", state->working_longitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude))); + snprintf(buf, sizeof(buf), "%c%05d", state->working_longitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude))); if (event.subsecond % 2) buf[state->active_digit] = ' '; watch_display_text(WATCH_POSITION_BOTTOM, buf); }