]> granicus.if.org Git - icu/commitdiff
ICU-12932 RBBI rule parsing, fix incorrect handling of node stack overflow.
authorAndy Heninger <andy.heninger@gmail.com>
Mon, 13 Feb 2017 21:04:32 +0000 (21:04 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Mon, 13 Feb 2017 21:04:32 +0000 (21:04 +0000)
X-SVN-Rev: 39669

icu4c/source/common/rbbiscan.cpp
icu4c/source/test/intltest/rbbitst.cpp
icu4c/source/test/intltest/rbbitst.h

index 060c0df62948325e940b3c0e60628750f8f52d46..e68e0529d02e33974ac79e4d72850c7b7de004d2 100644 (file)
@@ -1179,13 +1179,12 @@ RBBINode  *RBBIRuleScanner::pushNewNode(RBBINode::NodeType  t) {
     if (U_FAILURE(*fRB->fStatus)) {
         return NULL;
     }
-    fNodeStackPtr++;
-    if (fNodeStackPtr >= kStackSize) {
-        error(U_BRK_INTERNAL_ERROR);
+    if (fNodeStackPtr >= kStackSize - 1) {
+        error(U_BRK_RULE_SYNTAX);
         RBBIDebugPuts("RBBIRuleScanner::pushNewNode - stack overflow.");
-        *fRB->fStatus = U_BRK_INTERNAL_ERROR;
         return NULL;
     }
+    fNodeStackPtr++;
     fNodeStack[fNodeStackPtr] = new RBBINode(t);
     if (fNodeStack[fNodeStackPtr] == NULL) {
         *fRB->fStatus = U_MEMORY_ALLOCATION_ERROR;
index 5d8295014b2b3aee050bc09b7b7bd4dc0ea37604..a893f5c6480890088d6924d26696b89bc33c569c 100644 (file)
@@ -104,6 +104,7 @@ void RBBITest::runIndexedTest( int32_t index, UBool exec, const char* &name, cha
     TESTCASE_AUTO(TestBug7547);
     TESTCASE_AUTO(TestBug12797);
     TESTCASE_AUTO(TestBug12918);
+    TESTCASE_AUTO(TestBug12932);
     TESTCASE_AUTO_END;
 }
 
@@ -4665,13 +4666,32 @@ void RBBITest::TestBug12918() {
     ubrk_close(iter);
 }
 
+void RBBITest::TestBug12932() {
+    // Node Stack overflow in the RBBI rule parser caused a seg fault.
+    UnicodeString ruleStr(
+            "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("
+            "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((("
+            "(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))"
+            ")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"
+            ")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))"
+            ")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))");
+
+    UErrorCode status = U_ZERO_ERROR;
+    UParseError parseError;
+    RuleBasedBreakIterator rbbi(ruleStr, parseError, status);
+    if (status != U_BRK_RULE_SYNTAX) {
+        errln("%s:%d expected U_BRK_RULE_SYNTAX, got %s",
+                __FILE__, __LINE__, u_errorName(status));
+    }
+}
+
+
 //
 //  TestDebug    -  A place-holder test for debugging purposes.
 //                  For putting in fragments of other tests that can be invoked
 //                  for tracing  without a lot of unwanted extra stuff happening.
 //
 void RBBITest::TestDebug(void) {
-
 }
 
 void RBBITest::TestProperties() {
index d22b416d4865edf1a96240e25594475b10ea6fa8..025d3028d2310a5d221600c5bcb87c502868fb32 100644 (file)
@@ -77,6 +77,7 @@ public:
     void TestBug7547();
     void TestBug12797();
     void TestBug12918();
+    void TestBug12932();
 
     void TestDebug();
     void TestProperties();