]> granicus.if.org Git - icu/commitdiff
ICU-10874 bounds check on LocaleBased (note ICU-9762 to untangle LocaleBased)
authorSteven R. Loomis <srl@icu-project.org>
Wed, 25 Jun 2014 23:39:07 +0000 (23:39 +0000)
committerSteven R. Loomis <srl@icu-project.org>
Wed, 25 Jun 2014 23:39:07 +0000 (23:39 +0000)
X-SVN-Rev: 35950

icu4c/source/common/brkiter.cpp
icu4c/source/common/locbased.cpp
icu4c/source/common/locbased.h

index 5931ebf7fbd70fe796dbe1851edf5121f6722279..a4e4466808a3dae236d45bab302185bb070024c7 100644 (file)
@@ -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);
     }
 
index b3d911d0edc1a66b2471fe95e5ad6fba5f1f6dee..ba289621f9a99712b590417570417f8456400414 100644 (file)
@@ -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
     }
 }
 
index d9f8942071b1f3df20a36514d101756d95f33a4c..2e0400e3164dcda48b64a299b452702948aa00e5 100644 (file)
@@ -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);