From 4b0f5cfd774fd431f15858b15bd1152003f4d524 Mon Sep 17 00:00:00 2001 From: Antonio Cervone Date: Tue, 1 Dec 2015 10:59:22 +0100 Subject: [PATCH] check for end of input on every increment of the cursor --- json11.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/json11.cpp b/json11.cpp index f67fda5..3ea9a67 100644 --- a/json11.cpp +++ b/json11.cpp @@ -373,22 +373,35 @@ struct JsonParser { bool comment_found = false; if (str[i] == '/') { i++; + if (i == str.size()) + return fail("unexpected end of input inside comment", 0); if (str[i] == '/') { // inline comment i++; + if (i == str.size()) + return fail("unexpected end of input inside inline comment", 0); // advance until next line - while (str[i] != '\n') + while (str[i] != '\n') { i++; + if (i == str.size()) + return fail("unexpected end of input inside inline comment", 0); + } comment_found = true; } else if (str[i] == '*') { // multiline comment i++; + if (i == str.size()) + return fail("unexpected end of input inside multi-line comment", 0); // advance until closing tokens while (!(str[i] == '*' && str[i+1] == '/')) { + i++; if (i == str.size()) return fail( "unexpected end of input inside multi-line comment", 0); - i++;} + } i += 2; + if (i == str.size()) + return fail( + "unexpected end of input inside multi-line comment", 0); comment_found = true; } else