ICU-6132 Check null pointer allocation and perform appropriate actions in regexst.cpp, remtrans.cpp, and repattrn.cpp.
X-SVN-Rev: 23235
This commit is contained in:
parent
82033615bf
commit
5bdd0a03d1
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// regexst.h
|
// regexst.h
|
||||||
//
|
//
|
||||||
// Copyright (C) 2004-2007, International Business Machines Corporation and others.
|
// Copyright (C) 2004-2008, International Business Machines Corporation and others.
|
||||||
// All Rights Reserved.
|
// All Rights Reserved.
|
||||||
//
|
//
|
||||||
// This file contains class RegexStaticSets
|
// This file contains class RegexStaticSets
|
||||||
@ -167,6 +167,20 @@ fRuleDigitsAlias(NULL)
|
|||||||
fPropSets[URX_GC_T] = new UnicodeSet(UnicodeString(TRUE, gGC_TPattern, -1), *status);
|
fPropSets[URX_GC_T] = new UnicodeSet(UnicodeString(TRUE, gGC_TPattern, -1), *status);
|
||||||
fPropSets[URX_GC_LV] = new UnicodeSet(UnicodeString(TRUE, gGC_LVPattern, -1), *status);
|
fPropSets[URX_GC_LV] = new UnicodeSet(UnicodeString(TRUE, gGC_LVPattern, -1), *status);
|
||||||
fPropSets[URX_GC_LVT] = new UnicodeSet(UnicodeString(TRUE, gGC_LVTPattern, -1), *status);
|
fPropSets[URX_GC_LVT] = new UnicodeSet(UnicodeString(TRUE, gGC_LVTPattern, -1), *status);
|
||||||
|
|
||||||
|
// Check for null pointers
|
||||||
|
if (fPropSets[URX_ISWORD_SET] == NULL ||
|
||||||
|
fPropSets[URX_ISSPACE_SET] == NULL ||
|
||||||
|
fPropSets[URX_GC_EXTEND] == NULL ||
|
||||||
|
fPropSets[URX_GC_CONTROL] == NULL ||
|
||||||
|
fPropSets[URX_GC_L] == NULL ||
|
||||||
|
fPropSets[URX_GC_V] == NULL ||
|
||||||
|
fPropSets[URX_GC_T] == NULL ||
|
||||||
|
fPropSets[URX_GC_LV] == NULL ||
|
||||||
|
fPropSets[URX_GC_LVT] == NULL ) {
|
||||||
|
goto ExitConstrDeleteAll;
|
||||||
|
|
||||||
|
}
|
||||||
if (U_FAILURE(*status)) {
|
if (U_FAILURE(*status)) {
|
||||||
// Bail out if we were unable to create the above sets.
|
// Bail out if we were unable to create the above sets.
|
||||||
// The rest of the initialization needs them, so we cannot proceed.
|
// The rest of the initialization needs them, so we cannot proceed.
|
||||||
@ -185,6 +199,10 @@ fRuleDigitsAlias(NULL)
|
|||||||
// when finding grapheme cluster boundaries.
|
// when finding grapheme cluster boundaries.
|
||||||
//
|
//
|
||||||
fPropSets[URX_GC_NORMAL] = new UnicodeSet(0, UnicodeSet::MAX_VALUE);
|
fPropSets[URX_GC_NORMAL] = new UnicodeSet(0, UnicodeSet::MAX_VALUE);
|
||||||
|
// Null pointer check
|
||||||
|
if (fPropSets[URX_GC_NORMAL] == NULL) {
|
||||||
|
goto ExitConstrDeleteAll;
|
||||||
|
}
|
||||||
fPropSets[URX_GC_NORMAL]->remove(0xac00, 0xd7a4);
|
fPropSets[URX_GC_NORMAL]->remove(0xac00, 0xd7a4);
|
||||||
fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_CONTROL]);
|
fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_CONTROL]);
|
||||||
fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_L]);
|
fPropSets[URX_GC_NORMAL]->removeAll(*fPropSets[URX_GC_L]);
|
||||||
@ -203,12 +221,47 @@ fRuleDigitsAlias(NULL)
|
|||||||
// Sets used while parsing rules, but not referenced from the parse state table
|
// Sets used while parsing rules, but not referenced from the parse state table
|
||||||
fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status);
|
fRuleSets[kRuleSet_rule_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_rule_char_pattern, -1), *status);
|
||||||
fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_digit_char_pattern, -1), *status);
|
fRuleSets[kRuleSet_digit_char-128] = new UnicodeSet(UnicodeString(TRUE, gRuleSet_digit_char_pattern, -1), *status);
|
||||||
|
//Check for null pointers
|
||||||
|
if (fRuleSets[kRuleSet_rule_char-128] == NULL ||
|
||||||
|
fRuleSets[kRuleSet_digit_char-128] == NULL) {
|
||||||
|
goto ExitConstrDeleteAll;
|
||||||
|
}
|
||||||
fRuleDigitsAlias = fRuleSets[kRuleSet_digit_char-128];
|
fRuleDigitsAlias = fRuleSets[kRuleSet_digit_char-128];
|
||||||
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
|
for (i=0; i<(int32_t)(sizeof(fRuleSets)/sizeof(fRuleSets[0])); i++) {
|
||||||
if (fRuleSets[i]) {
|
if (fRuleSets[i]) {
|
||||||
fRuleSets[i]->compact();
|
fRuleSets[i]->compact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return; // If we reached this point, everything is fine so just exit
|
||||||
|
|
||||||
|
ExitConstrDeleteAll: // Remove fPropSets and fRuleSets and return error
|
||||||
|
delete fPropSets[URX_ISWORD_SET];
|
||||||
|
delete fPropSets[URX_ISSPACE_SET];
|
||||||
|
delete fPropSets[URX_GC_EXTEND];
|
||||||
|
delete fPropSets[URX_GC_CONTROL];
|
||||||
|
delete fPropSets[URX_GC_L];
|
||||||
|
delete fPropSets[URX_GC_V];
|
||||||
|
delete fPropSets[URX_GC_T];
|
||||||
|
delete fPropSets[URX_GC_LV];
|
||||||
|
delete fPropSets[URX_GC_LVT];
|
||||||
|
delete fPropSets[URX_GC_NORMAL];
|
||||||
|
fPropSets[URX_ISWORD_SET] = NULL;
|
||||||
|
fPropSets[URX_ISSPACE_SET] = NULL;
|
||||||
|
fPropSets[URX_GC_EXTEND] = NULL;
|
||||||
|
fPropSets[URX_GC_CONTROL] = NULL;
|
||||||
|
fPropSets[URX_GC_L] = NULL;
|
||||||
|
fPropSets[URX_GC_V] = NULL;
|
||||||
|
fPropSets[URX_GC_T] = NULL;
|
||||||
|
fPropSets[URX_GC_LV] = NULL;
|
||||||
|
fPropSets[URX_GC_LVT] = NULL;
|
||||||
|
fPropSets[URX_GC_NORMAL] = NULL;
|
||||||
|
|
||||||
|
delete fRuleSets[kRuleSet_rule_char-128];
|
||||||
|
delete fRuleSets[kRuleSet_digit_char-128];
|
||||||
|
fRuleSets[kRuleSet_rule_char-128] = NULL;
|
||||||
|
fRuleSets[kRuleSet_digit_char-128] = NULL;
|
||||||
|
|
||||||
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -252,6 +305,10 @@ void RegexStaticSets::initGlobals(UErrorCode *status) {
|
|||||||
UMTX_CHECK(NULL, gStaticSets, p);
|
UMTX_CHECK(NULL, gStaticSets, p);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
p = new RegexStaticSets(status);
|
p = new RegexStaticSets(status);
|
||||||
|
if (p == NULL) {
|
||||||
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (U_FAILURE(*status)) {
|
if (U_FAILURE(*status)) {
|
||||||
delete p;
|
delete p;
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Copyright (c) 2001-2005, International Business Machines
|
* Copyright (c) 2001-2008, International Business Machines
|
||||||
* Corporation and others. All Rights Reserved.
|
* Corporation and others. All Rights Reserved.
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
* Date Name Description
|
* Date Name Description
|
||||||
@ -47,7 +47,7 @@ RemoveTransliterator::~RemoveTransliterator() {}
|
|||||||
|
|
||||||
Transliterator* RemoveTransliterator::clone(void) const {
|
Transliterator* RemoveTransliterator::clone(void) const {
|
||||||
Transliterator* result = new RemoveTransliterator();
|
Transliterator* result = new RemoveTransliterator();
|
||||||
if (getFilter() != 0) {
|
if (result != NULL && getFilter() != 0) {
|
||||||
result->adoptFilter((UnicodeFilter*)(getFilter()->clone()));
|
result->adoptFilter((UnicodeFilter*)(getFilter()->clone()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
/*
|
/*
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
* Copyright (C) 2002-2007 International Business Machines Corporation *
|
* Copyright (C) 2002-2008 International Business Machines Corporation *
|
||||||
* and others. All rights reserved. *
|
* and others. All rights reserved. *
|
||||||
***************************************************************************
|
***************************************************************************
|
||||||
*/
|
*/
|
||||||
@ -99,6 +99,10 @@ RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
|
|||||||
int32_t i;
|
int32_t i;
|
||||||
int32_t numSets = other.fSets->size();
|
int32_t numSets = other.fSets->size();
|
||||||
fSets8 = new Regex8BitSet[numSets];
|
fSets8 = new Regex8BitSet[numSets];
|
||||||
|
if (fSets8 == NULL) {
|
||||||
|
fDeferredStatus = U_MEMORY_ALLOCATION_ERROR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
for (i=1; i<numSets; i++) {
|
for (i=1; i<numSets; i++) {
|
||||||
if (U_FAILURE(fDeferredStatus)) {
|
if (U_FAILURE(fDeferredStatus)) {
|
||||||
return *this;
|
return *this;
|
||||||
@ -424,7 +428,11 @@ int32_t RegexPattern::split(const UnicodeString &input,
|
|||||||
};
|
};
|
||||||
|
|
||||||
RegexMatcher m(this);
|
RegexMatcher m(this);
|
||||||
int32_t r = m.split(input, dest, destCapacity, status);
|
int32_t r = 0;
|
||||||
|
// Check m's status to make sure all is ok.
|
||||||
|
if (U_SUCCESS(m.fDeferredStatus)) {
|
||||||
|
r = m.split(input, dest, destCapacity, status);
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user