vala: fix handling of unterminated strings.
authorSimon Tatham <anakin@pobox.com>
Fri, 10 May 2019 22:45:37 +0000 (23:45 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 13 May 2019 14:40:47 +0000 (15:40 +0100)
This fixes the two test cases in Ben Harris's unmerged PR #359.

vala/reader.vala

index caf400b..de0c63e 100644 (file)
@@ -117,7 +117,7 @@ class Mal.Reader : GLib.Object {
         if (token.has_prefix(":"))
             return new Mal.Keyword(token[1:token.length]);
         if (token.has_prefix("\"")) {
-            if (!token.has_suffix("\""))
+            if (token.length < 2 || !token.has_suffix("\""))
                 throw new Mal.Error.BAD_TOKEN(
                     poserr("end of input in mid-string"));
 
@@ -129,6 +129,9 @@ class Mal.Reader : GLib.Object {
 
             while ((pos = token.index_of ("\\", end)) != -1) {
                 strval += token[end:pos];
+                if (token.length - pos < 2)
+                    throw new Mal.Error.BAD_TOKEN(
+                        poserr("end of input in mid-string"));
                 switch (token[pos:pos+2]) {
                 case "\\\\":
                     strval += "\\"; break;