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
This commit is contained in:
Dave Chapman 2006-04-22 09:02:59 +00:00
parent 65c15eb50b
commit 9f34872df0

View file

@ -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)
{