ICU-10459 Fix segfault in uregex_group() when match is in invalid state.
X-SVN-Rev: 34559
This commit is contained in:
parent
2007dc91e7
commit
045919648e
File diff suppressed because it is too large
Load Diff
@ -680,8 +680,11 @@ uregex_group(URegularExpression *regexp2,
|
|||||||
}
|
}
|
||||||
return fullLength;
|
return fullLength;
|
||||||
} else {
|
} else {
|
||||||
|
int32_t result = 0;
|
||||||
UText *groupText = uregex_groupUTextDeep(regexp2, groupNum, NULL, status);
|
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);
|
utext_close(groupText);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "unicode/uchar.h"
|
#include "unicode/uchar.h"
|
||||||
#include "unicode/ucnv.h"
|
#include "unicode/ucnv.h"
|
||||||
#include "unicode/uniset.h"
|
#include "unicode/uniset.h"
|
||||||
|
#include "unicode/uregex.h"
|
||||||
#include "unicode/ustring.h"
|
#include "unicode/ustring.h"
|
||||||
#include "regextst.h"
|
#include "regextst.h"
|
||||||
#include "uvector.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";
|
case 21: name = "Bug 9283";
|
||||||
if (exec) Bug9283();
|
if (exec) Bug9283();
|
||||||
break;
|
break;
|
||||||
|
case 22: name = "Bug10459";
|
||||||
|
if (exec) Bug10459();
|
||||||
|
break;
|
||||||
|
|
||||||
default: name = "";
|
default: name = "";
|
||||||
break; //needed to end loop
|
break; //needed to end loop
|
||||||
@ -207,6 +211,7 @@ const char* RegexTest::extractToAssertBuf(const UnicodeString& message) {
|
|||||||
return ASSERT_BUF;
|
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);}
|
#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 */
|
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/********************************************************************
|
/********************************************************************
|
||||||
* COPYRIGHT:
|
* COPYRIGHT:
|
||||||
* Copyright (c) 2002-2012, International Business Machines Corporation and
|
* Copyright (c) 2002-2013, International Business Machines Corporation and
|
||||||
* others. All Rights Reserved.
|
* others. All Rights Reserved.
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ public:
|
|||||||
virtual void Bug7029();
|
virtual void Bug7029();
|
||||||
virtual void Bug9283();
|
virtual void Bug9283();
|
||||||
virtual void CheckInvBufSize();
|
virtual void CheckInvBufSize();
|
||||||
|
virtual void Bug10459();
|
||||||
|
|
||||||
// The following functions are internal to the regexp tests.
|
// The following functions are internal to the regexp tests.
|
||||||
virtual void assertUText(const char *expected, UText *actual, const char *file, int line);
|
virtual void assertUText(const char *expected, UText *actual, const char *file, int line);
|
||||||
|
Loading…
Reference in New Issue
Block a user