From 2b30a9fed85448b234b2da5553ae18e4253d8536 Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Mon, 24 Mar 2025 23:40:56 +0100 Subject: [PATCH] sb_create_from_settings: Fix crash when ui viewport setting malformed The 'Purple_Glow_V3' theme uses the following 'UI viewport' setting which is missing a comma after the viewport height: ui viewport: 0,0,271,212-,-,- The setting is actually ignored when loading this theme, since a UI viewport is already defined in the supplied SBS file. Rockbox will crash, though, when and if the next theme that is loaded resets the SBS by setting it to "-", but doesn't adjust the UI viewport setting at the same time. To fix, use default UI viewport when encountering fewer parameters than expected for the UI viewport setting. Change-Id: I2648565ac59369ce8ab18d8e84b7fa69ad767f25 --- apps/gui/statusbar-skinned.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c index a40dbbc31d..52fc17deaf 100644 --- a/apps/gui/statusbar-skinned.c +++ b/apps/gui/statusbar-skinned.c @@ -252,22 +252,28 @@ char* sb_create_from_settings(enum screen_type screen) comma = strchr(comma+1, ','); } while (comma && param_count < 6); - if (comma) + if (comma && strchr(comma+1, ',')) { char *end = comma; char fg[8], bg[8]; int i = 0; comma++; - while (*comma != ',') + while (*comma != ',' && i < (int) sizeof(fg) - 1) fg[i++] = *comma++; fg[i] = '\0'; comma++; i=0; - while (*comma != ')') + while (*comma != ')' && i < (int) sizeof(bg) - 1) bg[i++] = *comma++; bg[i] = '\0'; len += snprintf(end, remaining-len, ") %%Vf(%s) %%Vb(%s)\n", fg, bg); } + else + { + ptr2[0] = '-'; + ptr2[1] = '\0'; + } } - else + + if (!ptr2[0] || ptr2[0] == '-') { int y = 0, height; switch (bar_position)