]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Fix parsing of "-Infinity" when the "-" and "Infinity" are split across multiple...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 27 Nov 2017 05:04:33 +0000 (00:04 -0500)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Mon, 27 Nov 2017 05:04:33 +0000 (00:04 -0500)
Add several additional test cases for partial parsing of infinity values.

json_tokener.c
tests/test_parse.c

index 2a924561b54796bc735e6ca511ddf359a4b25aa0..4aaa89f195060b99c1b2755066cf1615d5be7db3 100644 (file)
@@ -763,7 +763,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
           printbuf_memappend_fast(tok->pb, case_start, case_len);
 
        // Check for -Infinity
-       if (tok->pb->buf[0] == '-' && case_len == 1 &&
+       if (tok->pb->buf[0] == '-' && case_len <= 1 &&
            (c == 'i' || c == 'I'))
        {
                state = json_tokener_state_inf;
index aa02251ee83b085f9542fe5cfe6c9393410defe3..cac8e52670e6794ae7d271dd5ce7aaed00faa4da 100644 (file)
@@ -197,6 +197,40 @@ struct incremental_step {
        { "null",              4, 4, json_tokener_continue, 1 },
        { "null",              5, 4, json_tokener_success, 1 },
 
+       { "Infinity",          9, 8, json_tokener_success, 1 },
+       { "infinity",          9, 8, json_tokener_success, 1 },
+       { "-infinity",        10, 9, json_tokener_success, 1 },
+       { "infinity",          9, 0, json_tokener_error_parse_unexpected, 3 },
+       { "-infinity",        10, 1, json_tokener_error_parse_unexpected, 3 },
+
+       { "inf",               3, 3, json_tokener_continue, 0 },
+       { "inity",             6, 5, json_tokener_success, 1 },
+       { "-inf",              4, 4, json_tokener_continue, 0 },
+       { "inity",             6, 5, json_tokener_success, 1 },
+
+       { "i",                 1, 1, json_tokener_continue, 0 },
+       { "n",                 1, 1, json_tokener_continue, 0 },
+       { "f",                 1, 1, json_tokener_continue, 0 },
+       { "i",                 1, 1, json_tokener_continue, 0 },
+       { "n",                 1, 1, json_tokener_continue, 0 },
+       { "i",                 1, 1, json_tokener_continue, 0 },
+       { "t",                 1, 1, json_tokener_continue, 0 },
+       { "y",                 1, 1, json_tokener_continue, 0 },
+       { "",                  1, 0, json_tokener_success, 1 },
+
+       { "-",                 1, 1, json_tokener_continue, 0 },
+       { "inf",               3, 3, json_tokener_continue, 0 },
+       { "ini",               3, 3, json_tokener_continue, 0 },
+       { "ty",                3, 2, json_tokener_success, 1 },
+
+       { "-",                 1, 1, json_tokener_continue, 0 },
+       { "i",                 1, 1, json_tokener_continue, 0 },
+       { "nfini",             5, 5, json_tokener_continue, 0 },
+       { "ty",                3, 2, json_tokener_success, 1 },
+
+       { "-i",                2, 2, json_tokener_continue, 0 },
+       { "nfinity",           8, 7, json_tokener_success, 1 },
+
        /* offset=1 because "n" is the start of "null".  hmm... */
        { "noodle",            7, 1, json_tokener_error_parse_null, 1 },
        /* offset=2 because "na" is the start of "nan".  hmm... */