From c567c8c1b1769c8bb106177830e5bd754f73d1ac Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Thu, 26 Mar 2009 23:04:40 +0000 Subject: [PATCH] ICU-6813 parameter validation to uregex_appendReplacement() X-SVN-Rev: 25660 --- icu4c/source/i18n/uregex.cpp | 2 +- icu4c/source/test/cintltst/reapits.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/icu4c/source/i18n/uregex.cpp b/icu4c/source/i18n/uregex.cpp index a2e85208282..c805df63fbd 100644 --- a/icu4c/source/i18n/uregex.cpp +++ b/icu4c/source/i18n/uregex.cpp @@ -883,7 +883,7 @@ int32_t RegexCImpl::appendReplacement(URegularExpression *regexp, // A series of appendReplacements, appendTail need to correctly preflight // the buffer size when an overflow happens somewhere in the middle. UBool pendingBufferOverflow = FALSE; - if (*status == U_BUFFER_OVERFLOW_ERROR && *destCapacity == 0) { + if (*status == U_BUFFER_OVERFLOW_ERROR && destCapacity != NULL && *destCapacity == 0) { pendingBufferOverflow = TRUE; *status = U_ZERO_ERROR; } diff --git a/icu4c/source/test/cintltst/reapits.c b/icu4c/source/test/cintltst/reapits.c index b5c3eb559af..3dd2014f2ec 100644 --- a/icu4c/source/test/cintltst/reapits.c +++ b/icu4c/source/test/cintltst/reapits.c @@ -948,6 +948,15 @@ static void TestRegexCAPI(void) { TEST_ASSERT_SUCCESS(status); TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); + /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. */ + status = U_ZERO_ERROR; + uregex_find(re, 0, &status); + TEST_ASSERT_SUCCESS(status); + bufPtr = buf; + status = U_BUFFER_OVERFLOW_ERROR; + uregex_appendReplacement(re, repl, -1, &bufPtr, NULL, &status); + TEST_ASSERT(status == U_BUFFER_OVERFLOW_ERROR); + uregex_close(re); }