]> granicus.if.org Git - icu/commitdiff
ICU-11302 Proper error handling with utext_clone in regular expression implementation.
authorYoshito Umaoka <y.umaoka@gmail.com>
Mon, 13 Oct 2014 17:46:34 +0000 (17:46 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Mon, 13 Oct 2014 17:46:34 +0000 (17:46 +0000)
X-SVN-Rev: 36673

icu4c/source/i18n/regexcmp.cpp
icu4c/source/i18n/rematch.cpp
icu4c/source/i18n/repattrn.cpp

index 0816eecfff5c885ccd30ccec8ad1ead4284998e1..c6bc89f113f32cecd69b9645594bb96bad94ce1f 100644 (file)
@@ -138,6 +138,9 @@ void    RegexCompile::compile(
 
     // Prepare the RegexPattern object to receive the compiled pattern.
     fRXPat->fPattern        = utext_clone(fRXPat->fPattern, pat, FALSE, TRUE, fStatus);
+    if (U_FAILURE(*fStatus)) {
+        return;
+    }
     fRXPat->fStaticSets     = RegexStaticSets::gStaticSets->fPropSets;
     fRXPat->fStaticSets8    = RegexStaticSets::gStaticSets->fPropSets8;
 
index 4389985e9ed7d0e0a4033801f8ea39af3f800626..ce7d284618d78df12f6d2d19647c7d003dc82ee6 100644 (file)
@@ -1884,6 +1884,9 @@ RegexMatcher &RegexMatcher::reset(const UnicodeString &input) {
     if (fPattern->fNeedsAltInput) {
         fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
     }
+    if (U_FAILURE(fDeferredStatus)) {
+        return *this;
+    }
     fInputLength = utext_nativeLength(fInputText);
 
     reset();
@@ -1908,6 +1911,9 @@ RegexMatcher &RegexMatcher::reset(UText *input) {
     if (fInputText != input) {
         fInputText = utext_clone(fInputText, input, FALSE, TRUE, &fDeferredStatus);
         if (fPattern->fNeedsAltInput) fAltInputText = utext_clone(fAltInputText, fInputText, FALSE, TRUE, &fDeferredStatus);
+        if (U_FAILURE(fDeferredStatus)) {
+            return *this;
+        }
         fInputLength = utext_nativeLength(fInputText);
 
         delete fInput;
index 2bc7d0395dbca6435024d6006a39ccb4b8d938d2..7efd4cb8932cb60d5d2827748717bd2a4f98e6e5 100644 (file)
@@ -3,7 +3,7 @@
 //
 /*
 ***************************************************************************
-*   Copyright (C) 2002-2013 International Business Machines Corporation   *
+*   Copyright (C) 2002-2014 International Business Machines Corporation   *
 *   and others. All rights reserved.                                      *
 ***************************************************************************
 */
@@ -66,21 +66,29 @@ RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
     init();
 
     // Copy simple fields
-    if ( other.fPatternString == NULL ) {
+    fDeferredStatus   = other.fDeferredStatus;
+
+    if (U_FAILURE(fDeferredStatus)) {
+        return *this;
+    }
+
+    if (other.fPatternString == NULL) {
         fPatternString = NULL;
-        fPattern      = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
+        fPattern = utext_clone(fPattern, other.fPattern, FALSE, TRUE, &fDeferredStatus);
     } else {
         fPatternString = new UnicodeString(*(other.fPatternString));
-        UErrorCode status = U_ZERO_ERROR;
-        fPattern      = utext_openConstUnicodeString(NULL, fPatternString, &status);
-        if (U_FAILURE(status)) {
+        if (fPatternString == NULL) {
             fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
-            return *this;
+        } else {
+            fPattern = utext_openConstUnicodeString(NULL, fPatternString, &fDeferredStatus);
         }
     }
+    if (U_FAILURE(fDeferredStatus)) {
+        return *this;
+    }
+
     fFlags            = other.fFlags;
     fLiteralText      = other.fLiteralText;
-    fDeferredStatus   = other.fDeferredStatus;
     fMinMatchLen      = other.fMinMatchLen;
     fFrameSize        = other.fFrameSize;
     fDataSize         = other.fDataSize;