From: Yoshito Umaoka Date: Mon, 13 Oct 2014 17:46:34 +0000 (+0000) Subject: ICU-11302 Proper error handling with utext_clone in regular expression implementation. X-Git-Tag: milestone-59-0-1~1458 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff4fd29a21e9ed4115f514bbe71846175922724e;p=icu ICU-11302 Proper error handling with utext_clone in regular expression implementation. X-SVN-Rev: 36673 --- diff --git a/icu4c/source/i18n/regexcmp.cpp b/icu4c/source/i18n/regexcmp.cpp index 0816eecfff5..c6bc89f113f 100644 --- a/icu4c/source/i18n/regexcmp.cpp +++ b/icu4c/source/i18n/regexcmp.cpp @@ -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; diff --git a/icu4c/source/i18n/rematch.cpp b/icu4c/source/i18n/rematch.cpp index 4389985e9ed..ce7d284618d 100644 --- a/icu4c/source/i18n/rematch.cpp +++ b/icu4c/source/i18n/rematch.cpp @@ -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; diff --git a/icu4c/source/i18n/repattrn.cpp b/icu4c/source/i18n/repattrn.cpp index 2bc7d0395db..7efd4cb8932 100644 --- a/icu4c/source/i18n/repattrn.cpp +++ b/icu4c/source/i18n/repattrn.cpp @@ -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;