ICU-8486 UText not checking for Bogus UnicodeStrings, causing crash in regular expressions.
X-SVN-Rev: 29840
This commit is contained in:
parent
20112d92bd
commit
118efa19c6
@ -2620,20 +2620,9 @@ U_CDECL_END
|
||||
|
||||
U_CAPI UText * U_EXPORT2
|
||||
utext_openUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
||||
// TODO: use openConstUnicodeString, then add in the differences.
|
||||
//
|
||||
ut = utext_setup(ut, 0, status);
|
||||
ut = utext_openConstUnicodeString(ut, s, status);
|
||||
if (U_SUCCESS(*status)) {
|
||||
ut->pFuncs = &unistrFuncs;
|
||||
ut->context = s;
|
||||
ut->providerProperties = I32_FLAG(UTEXT_PROVIDER_STABLE_CHUNKS)|
|
||||
I32_FLAG(UTEXT_PROVIDER_WRITABLE);
|
||||
|
||||
ut->chunkContents = s->getBuffer();
|
||||
ut->chunkLength = s->length();
|
||||
ut->chunkNativeStart = 0;
|
||||
ut->chunkNativeLimit = ut->chunkLength;
|
||||
ut->nativeIndexingLimit = ut->chunkLength;
|
||||
ut->providerProperties |= I32_FLAG(UTEXT_PROVIDER_WRITABLE);
|
||||
}
|
||||
return ut;
|
||||
}
|
||||
@ -2642,6 +2631,13 @@ utext_openUnicodeString(UText *ut, UnicodeString *s, UErrorCode *status) {
|
||||
|
||||
U_CAPI UText * U_EXPORT2
|
||||
utext_openConstUnicodeString(UText *ut, const UnicodeString *s, UErrorCode *status) {
|
||||
if (U_SUCCESS(*status) && s->isBogus()) {
|
||||
// The UnicodeString is bogus, but we still need to detach the UText
|
||||
// from whatever it was hooked to before, if anything.
|
||||
utext_openUChars(ut, NULL, 0, status);
|
||||
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return ut;
|
||||
}
|
||||
ut = utext_setup(ut, 0, status);
|
||||
// note: use the standard (writable) function table for UnicodeString.
|
||||
// The flag settings disable writing, so having the functions in
|
||||
|
@ -108,6 +108,9 @@ void RegexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, ch
|
||||
case 17: name = "Bug 7740";
|
||||
if (exec) Bug7740();
|
||||
break;
|
||||
case 18: name = "Bug 8479";
|
||||
if (exec) Bug8479();
|
||||
break;
|
||||
|
||||
default: name = "";
|
||||
break; //needed to end loop
|
||||
@ -5046,7 +5049,24 @@ void RegexTest::Bug7740() {
|
||||
delete m;
|
||||
}
|
||||
|
||||
// Bug 8479: was crashing whith a Bogus UnicodeString as input.
|
||||
|
||||
void RegexTest::Bug8479() {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
RegexMatcher* const pMatcher = new RegexMatcher("\\Aboo\\z", UREGEX_DOTALL|UREGEX_CASE_INSENSITIVE, status);
|
||||
REGEX_CHECK_STATUS;
|
||||
if (U_SUCCESS(status))
|
||||
{
|
||||
UnicodeString str;
|
||||
str.setToBogus();
|
||||
pMatcher->reset(str);
|
||||
status = U_ZERO_ERROR;
|
||||
pMatcher->matches(status);
|
||||
REGEX_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR);
|
||||
delete pMatcher;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 2002-2010, International Business Machines Corporation and
|
||||
* Copyright (c) 2002-2011, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
|
||||
@ -43,6 +43,7 @@ public:
|
||||
virtual void PreAllocatedUTextCAPI();
|
||||
virtual void Bug7651();
|
||||
virtual void Bug7740();
|
||||
virtual void Bug8479();
|
||||
|
||||
// The following functions are internal to the regexp tests.
|
||||
virtual void assertUText(const char *expected, UText *actual, const char *file, int line);
|
||||
|
Loading…
Reference in New Issue
Block a user