summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2007-05-02 11:39:46 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2007-05-02 11:39:46 +0000
commit378a140ae2bdd373ec64066f5afe70b65f237d66 (patch)
treee518e852dbb541380a54b537debdc242ebc91aad
parent3494b2118b5fcd83ae1ed7c5d429522c79b7c448 (diff)
downloadrockbox-378a140ae2bdd373ec64066f5afe70b65f237d66.zip
rockbox-378a140ae2bdd373ec64066f5afe70b65f237d66.tar.gz
rockbox-378a140ae2bdd373ec64066f5afe70b65f237d66.tar.bz2
rockbox-378a140ae2bdd373ec64066f5afe70b65f237d66.tar.xz
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
-rw-r--r--apps/gui/wps_parser.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 67b8a6f..ee16de3 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