From 378a140ae2bdd373ec64066f5afe70b65f237d66 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Wed, 2 May 2007 11:39:46 +0000 Subject: Add a check for unclosed conditionals at the end of the WPS parsing in case we didn't reach the end of the file. Also a few minor other changes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13303 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/wps_parser.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index 67b8a6f9ca..ee16de330a 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c @@ -770,12 +770,11 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) unsigned int len = 1; const char *string_start = wps_bufptr - 1; - /* continue until we hit something that ends the string - or we run out of memory */ + /* find the length of the string */ while (wps_bufptr && *wps_bufptr != '#' && - *wps_bufptr != '%' && *wps_bufptr != ';' && - *wps_bufptr != '<' && *wps_bufptr != '>' && - *wps_bufptr != '|' && *wps_bufptr != '\n') + *wps_bufptr != '%' && *wps_bufptr != ';' && + *wps_bufptr != '<' && *wps_bufptr != '>' && + *wps_bufptr != '|' && *wps_bufptr != '\n') { wps_bufptr++; len++; @@ -788,7 +787,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) for (i = 0, str = data->strings, found = false; i < data->num_strings && !(found = (strlen(*str) == len && - strncmp(string_start, *str, len) == 0)); + strncmp(string_start, *str, len) == 0)); i++, str++); /* If a matching string is found, found is true and i is the index of the string. If not, found is false */ @@ -796,23 +795,24 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) /* If it's NOT a duplicate, do nothing if we already have too many unique strings */ if (found || - (stringbuf_used < STRING_BUFFER_SIZE - 1 && - data->num_strings < WPS_MAX_STRINGS)) + (stringbuf_used < STRING_BUFFER_SIZE - 1 && + data->num_strings < WPS_MAX_STRINGS)) { if (!found) { /* new string */ - /* truncate? */ + + /* truncate? */ if (stringbuf_used + len > STRING_BUFFER_SIZE - 1) len = STRING_BUFFER_SIZE - stringbuf_used - 1; - + strncpy(stringbuf, string_start, len); - + *(stringbuf + len) = '\0'; + data->strings[data->num_strings] = stringbuf; stringbuf += len + 1; stringbuf_used += len + 1; - data->tokens[data->num_tokens].value.i = - data->num_strings; + data->tokens[data->num_tokens].value.i = data->num_strings; data->num_strings++; } else @@ -828,6 +828,9 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr) } } + if (level >= 0) /* there are unclosed conditionals */ + fail = PARSE_FAIL_UNCLOSED_COND; + #ifdef DEBUG print_debug_info(data, fail, line); #endif -- cgit v1.2.3