ICU-10459 Fix segfault in uregex_group() when match is in invalid state.

X-SVN-Rev: 34559
This commit is contained in:
Andy Heninger 2013-10-11 20:59:39 +00:00
parent 2007dc91e7
commit 045919648e
4 changed files with 429 additions and 426 deletions

File diff suppressed because it is too large Load Diff

View File

@ -680,8 +680,11 @@ uregex_group(URegularExpression *regexp2,
}
return fullLength;
} else {
int32_t result = 0;
UText *groupText = uregex_groupUTextDeep(regexp2, groupNum, NULL, status);
int32_t result = utext_extract(groupText, 0, utext_nativeLength(groupText), dest, destCapacity, status);
if (U_SUCCESS(*status)) {
result = utext_extract(groupText, 0, utext_nativeLength(groupText), dest, destCapacity, status);
}
utext_close(groupText);
return result;
}

View File

@ -27,6 +27,7 @@
#include "unicode/uchar.h"
#include "unicode/ucnv.h"
#include "unicode/uniset.h"
#include "unicode/uregex.h"
#include "unicode/ustring.h"
#include "regextst.h"
#include "uvector.h"
@ -131,6 +132,9 @@ void RegexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, ch
case 21: name = "Bug 9283";
if (exec) Bug9283();
break;
case 22: name = "Bug10459";
if (exec) Bug10459();
break;
default: name = "";
break; //needed to end loop
@ -207,6 +211,7 @@ const char* RegexTest::extractToAssertBuf(const UnicodeString& message) {
return ASSERT_BUF;
}
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
#define REGEX_VERBOSE_TEXT(text) {char buf[200];utextToPrintable(buf,sizeof(buf)/sizeof(buf[0]),text);logln("%s:%d: UText %s=\"%s\"", __FILE__, __LINE__, #text, buf);}
@ -5229,5 +5234,36 @@ void RegexTest::CheckInvBufSize() {
}
}
void RegexTest::Bug10459() {
UErrorCode status = U_ZERO_ERROR;
UnicodeString patternString("(txt)");
UnicodeString txtString("txt");
UText *utext_pat = utext_openUnicodeString(NULL, &patternString, &status);
REGEX_CHECK_STATUS;
UText *utext_txt = utext_openUnicodeString(NULL, &txtString, &status);
REGEX_CHECK_STATUS;
URegularExpression *icu_re = uregex_openUText(utext_pat, 0, NULL, &status);
REGEX_CHECK_STATUS;
uregex_setUText(icu_re, utext_txt, &status);
REGEX_CHECK_STATUS;
// The bug was that calling uregex_group() before doing a matching operation
// was causing a segfault. Only for Regular Expressions created from UText.
// It should set an U_REGEX_INVALID_STATE.
UChar buf[100];
int32_t len = uregex_group(icu_re, 0, buf, LENGTHOF(buf), &status);
REGEX_ASSERT(status == U_REGEX_INVALID_STATE);
REGEX_ASSERT(len == 0);
uregex_close(icu_re);
utext_close(utext_pat);
utext_close(utext_txt);
}
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 2002-2012, International Business Machines Corporation and
* Copyright (c) 2002-2013, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -47,6 +47,7 @@ public:
virtual void Bug7029();
virtual void Bug9283();
virtual void CheckInvBufSize();
virtual void Bug10459();
// The following functions are internal to the regexp tests.
virtual void assertUText(const char *expected, UText *actual, const char *file, int line);