From eab3301711168ac934c27c9c331a9742ac848b1c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 25 Jan 2011 01:01:48 +0000 Subject: Fix crash when parsing malformed numbers. Add bad test cases (reach 95% test coverage). git-svn-id: http://svn.drobilla.net/serd/trunk@59 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/reader.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/reader.c b/src/reader.c index 468e0f21..e0ffd816 100644 --- a/src/reader.c +++ b/src/reader.c @@ -809,19 +809,20 @@ except: return 0; } - -static Ref +static bool read_0_9(SerdReader reader, Ref str, bool at_least_one) { uint8_t c; if (at_least_one) { - TRY_RET(is_digit((c = peek_byte(reader)))); + if (!is_digit((c = peek_byte(reader)))) { + return error(reader, "expected digit\n"); + } push_byte(reader, str, eat_byte(reader, c)); } while (is_digit((c = peek_byte(reader)))) { push_byte(reader, str, eat_byte(reader, c)); } - return str; + return true; } // [19] exponent ::= [eE] ('-' | '+')? [0-9]+ @@ -849,21 +850,21 @@ read_number(SerdReader reader, Node* dest) has_decimal = true; // decimal case 2 (e.g. '.0' or `-.0' or `+.0') push_byte(reader, str, eat_byte(reader, c)); - TRY_THROW(str = read_0_9(reader, str, true)); + TRY_THROW(read_0_9(reader, str, true)); } else { // all other cases ::= ( '-' | '+' ) [0-9]+ ( . )? ( [0-9]+ )? ... - TRY_THROW(str = read_0_9(reader, str, true)); + TRY_THROW(read_0_9(reader, str, true)); if ((c = peek_byte(reader)) == '.') { has_decimal = true; push_byte(reader, str, eat_byte(reader, c)); - TRY_THROW(str = read_0_9(reader, str, false)); + TRY_THROW(read_0_9(reader, str, false)); } } c = peek_byte(reader); if (c == 'e' || c == 'E') { // double push_byte(reader, str, eat_byte(reader, c)); - str = read_0_9(reader, str, true); + read_0_9(reader, str, true); datatype = push_string(reader, XSD_DOUBLE, strlen(XSD_DOUBLE) + 1); } else if (has_decimal) { datatype = push_string(reader, XSD_DECIMAL, strlen(XSD_DECIMAL) + 1); -- cgit v1.2.1