From 9f34872df065d2a41e9eeefc171afd0323c5b0f4 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Sat, 22 Apr 2006 09:02:59 +0000 Subject: Make the get_image_id() function more robust, and catch a parsing error when parsing the %x tags. This prevents Rockbox crashing when presented with an incorrect %x|filename.bmp| WPS line. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9755 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'apps') diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 41e20ec..fe059f4 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -84,10 +84,11 @@ static char* skip_utf8_bom(char* buf) static int get_image_id(int c) { if(c >= 'a' && c <= 'z') - c -= 'a'; - if(c >= 'A' && c <= 'Z') - c = c - 'A' + 26; - return c; + return c - 'a'; + else if(c >= 'A' && c <= 'Z') + return c - 'A' + 26; + else + return -1; } #endif @@ -287,6 +288,10 @@ bool wps_data_preload_tags(struct wps_data *data, char *buf, { /* get filename */ pos = strchr(ptr, '|'); + + if (pos == NULL) + return false; + if ((pos - ptr) < (int)sizeof(imgname)-ROCKBOX_DIR_LEN-2) { -- cgit v1.1