From: Steven R. Loomis Date: Wed, 25 Jun 2014 23:39:07 +0000 (+0000) Subject: ICU-10874 bounds check on LocaleBased (note ICU-9762 to untangle LocaleBased) X-Git-Tag: milestone-59-0-1~1837 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=40f501ff5982e6e5f080c45a709628c0055dc3e4;p=icu ICU-10874 bounds check on LocaleBased (note ICU-9762 to untangle LocaleBased) X-SVN-Rev: 35950 --- diff --git a/icu4c/source/common/brkiter.cpp b/icu4c/source/common/brkiter.cpp index 5931ebf7fbd..a4e4466808a 100644 --- a/icu4c/source/common/brkiter.cpp +++ b/icu4c/source/common/brkiter.cpp @@ -35,6 +35,7 @@ #include "uresimp.h" #include "uassert.h" #include "ubrkimpl.h" +#include "charstr.h" // ***************************************************************************** // class BreakIterator @@ -52,7 +53,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, int32_t kind, { char fnbuff[256]; char ext[4]={'\0'}; - char actualLocale[ULOC_FULLNAME_CAPACITY]; + CharString actualLocale; int32_t size; const UChar* brkfname = NULL; UResourceBundle brkRulesStack; @@ -93,9 +94,7 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, int32_t kind, // Use the string if we found it if (U_SUCCESS(status) && brkfname) { - uprv_strncpy(actualLocale, - ures_getLocaleInternal(brkName, &status), - sizeof(actualLocale)/sizeof(actualLocale[0])); + actualLocale.append(ures_getLocaleInternal(brkName, &status), -1, status); UChar* extStart=u_strchr(brkfname, 0x002e); int len = 0; @@ -123,7 +122,8 @@ BreakIterator::buildInstance(const Locale& loc, const char *type, int32_t kind, // If there is a result, set the valid locale and actual locale, and the kind if (U_SUCCESS(status) && result != NULL) { U_LOCALE_BASED(locBased, *(BreakIterator*)result); - locBased.setLocaleIDs(ures_getLocaleByType(b, ULOC_VALID_LOCALE, &status), actualLocale); + locBased.setLocaleIDs(ures_getLocaleByType(b, ULOC_VALID_LOCALE, &status), + actualLocale.data()); result->setBreakType(kind); } diff --git a/icu4c/source/common/locbased.cpp b/icu4c/source/common/locbased.cpp index b3d911d0edc..ba289621f9a 100644 --- a/icu4c/source/common/locbased.cpp +++ b/icu4c/source/common/locbased.cpp @@ -36,10 +36,12 @@ const char* LocaleBased::getLocaleID(ULocDataLocaleType type, UErrorCode& status void LocaleBased::setLocaleIDs(const char* validID, const char* actualID) { if (validID != 0) { - uprv_strcpy(valid, validID); + uprv_strncpy(valid, validID, ULOC_FULLNAME_CAPACITY); + valid[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate } if (actualID != 0) { - uprv_strcpy(actual, actualID); + uprv_strncpy(actual, actualID, ULOC_FULLNAME_CAPACITY); + actual[ULOC_FULLNAME_CAPACITY-1] = 0; // always terminate } } diff --git a/icu4c/source/common/locbased.h b/icu4c/source/common/locbased.h index d9f8942071b..2e0400e3164 100644 --- a/icu4c/source/common/locbased.h +++ b/icu4c/source/common/locbased.h @@ -17,7 +17,7 @@ /** * Macro to declare a locale LocaleBased wrapper object for the given * object, which must have two members named `validLocale' and - * `actualLocale'. + * `actualLocale' of size ULOC_FULLNAME_CAPACITY */ #define U_LOCALE_BASED(varname, objname) \ LocaleBased varname((objname).validLocale, (objname).actualLocale);