Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Unified Diff: src/parser.cc

Issue 21078: RegExp parser: Fixed unchecked numeric overflow bug. (Closed)
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 97bb2f46b7e4adfed992076ad977cc9acdd81e2a..f6ab40bb792946e0dbe3fa9abe278709a322fafa 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3938,6 +3938,9 @@ bool RegExpParser::ParseBackReferenceIndex(int* index_out) {
// { DecimalDigits }
// { DecimalDigits , }
// { DecimalDigits , DecimalDigits }
+//
+// Returns true if parsing succeeds, and set the min_out and max_out
+// values. Values are set to RegExpTree::kInfinity if they overflow.
bool RegExpParser::ParseIntervalQuantifier(int* min_out, int* max_out) {
ASSERT_EQ(current(), '{');
int start = position();
@@ -3948,7 +3951,14 @@ bool RegExpParser::ParseIntervalQuantifier(int* min_out, int* max_out) {
return false;
}
while (IsDecimalDigit(current())) {
- min = 10 * min + (current() - '0');
+ int next = current() - '0';
+ if (min > (RegExpTree::kInfinity - next) / 10) {
+ // Overflow. Skip past remaining decimal digits and return -1.
+ do { Advance(); } while (IsDecimalDigit(current()));
Erik Corry 2009/02/05 11:59:36 Does this correctly handle hitting the end of the
Lasse Reichstein 2009/02/05 12:54:41 Yes. Reading current() at end of input is allowed.
+ min = RegExpTree::kInfinity;
+ break;
+ }
+ min = 10 * min + next;
Advance();
}
int max = 0;
@@ -3962,7 +3972,13 @@ bool RegExpParser::ParseIntervalQuantifier(int* min_out, int* max_out) {
Advance();
} else {
while (IsDecimalDigit(current())) {
- max = 10 * max + (current() - '0');
+ int next = current() - '0';
+ if (max > (RegExpTree::kInfinity - next) / 10) {
+ do { Advance(); } while (IsDecimalDigit(current()));
+ max = RegExpTree::kInfinity;;
+ break;
+ }
+ max = 10 * max + next;
Advance();
}
if (current() != '}') {
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698