]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
parser: check for std::out_of_range from stoul
authorJustin Viiret <justin.viiret@intel.com>
Fri, 3 Feb 2017 00:17:47 +0000 (11:17 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 04:58:46 +0000 (14:58 +1000)
src/parser/Parser.rl

index ea8e88a95b6c6a2c0946a30c880850a4bd1da75b..6f4fd80a03bc559fc84247078091630072269061 100644 (file)
@@ -974,7 +974,12 @@ unichar readUtf8CodePoint4c(const char *s) {
 
               '\\o{' [0-7]+ '}' => {
                   string oct(ts + 3, te - ts - 4);
-                  unsigned long val = stoul(oct, nullptr, 8);
+                  unsigned long val;
+                  try {
+                      val = stoul(oct, nullptr, 8);
+                  } catch (const std::out_of_range &) {
+                      val = MAX_UNICODE + 1;
+                  }
                   if ((!mode.utf8 && val > 255) || val > MAX_UNICODE) {
                       throw LocatedParseError("Value in \\o{...} sequence is too large");
                   }
@@ -999,7 +1004,12 @@ unichar readUtf8CodePoint4c(const char *s) {
               # Unicode Hex
               '\\x{' xdigit+ '}' => {
                   string hex(ts + 3, te - ts - 4);
-                  unsigned long val = stoul(hex, nullptr, 16);
+                  unsigned long val;
+                  try {
+                      val = stoul(hex, nullptr, 16);
+                  } catch (const std::out_of_range &) {
+                      val = MAX_UNICODE + 1;
+                  }
                   if (val > MAX_UNICODE) {
                       throw LocatedParseError("Value in \\x{...} sequence is too large");
                   }
@@ -1488,7 +1498,12 @@ unichar readUtf8CodePoint4c(const char *s) {
               };
               '\\o{' [0-7]+ '}' => {
                   string oct(ts + 3, te - ts - 4);
-                  unsigned long val = stoul(oct, nullptr, 8);
+                  unsigned long val;
+                  try {
+                      val = stoul(oct, nullptr, 8);
+                  } catch (const std::out_of_range &) {
+                      val = MAX_UNICODE + 1;
+                  }
                   if ((!mode.utf8 && val > 255) || val > MAX_UNICODE) {
                       throw LocatedParseError("Value in \\o{...} sequence is too large");
                   }
@@ -1505,7 +1520,12 @@ unichar readUtf8CodePoint4c(const char *s) {
               # Unicode Hex
               '\\x{' xdigit+ '}' => {
                   string hex(ts + 3, te - ts - 4);
-                  unsigned long val = stoul(hex, nullptr, 16);
+                  unsigned long val;
+                  try {
+                      val = stoul(hex, nullptr, 16);
+                  } catch (const std::out_of_range &) {
+                      val = MAX_UNICODE + 1;
+                  }
                   if (val > MAX_UNICODE) {
                       throw LocatedParseError("Value in \\x{...} sequence is too large");
                   }