Skip to content

Commit b8391c6

Browse files
hirorogoSquash Bot
authored andcommitted
Fix use-after-free race in TransliteratorAlias compoundFilter
See #3913
1 parent d5db803 commit b8391c6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

icu4c/source/i18n/transreg.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ TransliteratorAlias::TransliteratorAlias(const UnicodeString& theAliasID,
8686
ID(),
8787
aliasesOrRules(theAliasID),
8888
transes(nullptr),
89-
compoundFilter(cpdFilter),
89+
compoundFilter(cpdFilter ? cpdFilter->clone() : nullptr),
9090
direction(UTRANS_FORWARD),
9191
type(TransliteratorAlias::SIMPLE) {
9292
}
@@ -98,7 +98,7 @@ TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
9898
ID(theID),
9999
aliasesOrRules(idBlocks),
100100
transes(adoptedTransliterators),
101-
compoundFilter(cpdFilter),
101+
compoundFilter(cpdFilter ? cpdFilter->clone() : nullptr),
102102
direction(UTRANS_FORWARD),
103103
type(TransliteratorAlias::COMPOUND) {
104104
}
@@ -116,6 +116,7 @@ TransliteratorAlias::TransliteratorAlias(const UnicodeString& theID,
116116

117117
TransliteratorAlias::~TransliteratorAlias() {
118118
delete transes;
119+
delete compoundFilter;
119120
}
120121

121122

@@ -132,7 +133,7 @@ Transliterator* TransliteratorAlias::create(UParseError& pe,
132133
return nullptr;
133134
}
134135
if (compoundFilter != nullptr)
135-
t->adoptFilter(compoundFilter->clone());
136+
t->adoptFilter(static_cast<UnicodeSet*>(compoundFilter->clone()));
136137
break;
137138
case COMPOUND:
138139
{

icu4c/source/i18n/transreg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ class TransliteratorAlias : public UMemory {
105105
// Here ID is the ID, aliasID is the idBlock, trans is the
106106
// contained RBT, and idSplitPoint is the offset in aliasID
107107
// where the contained RBT goes. compoundFilter is the
108-
// compound filter, and it is _not_ owned.
108+
// compound filter, and it is owned (cloned from entry).
109109
// 3. Rules
110110
// Here ID is the ID, aliasID is the rules string.
111111
// idSplitPoint is the UTransDirection.
112112
UnicodeString ID;
113113
UnicodeString aliasesOrRules;
114114
UVector* transes; // owned
115-
const UnicodeSet* compoundFilter; // alias
115+
UnicodeSet* compoundFilter; // owned
116116
UTransDirection direction;
117117
enum { SIMPLE, COMPOUND, RULES } type;
118118

0 commit comments

Comments
 (0)