]> granicus.if.org Git - icu/commitdiff
ICU-13394 nul-terminated buffer handling fixed from Chromium.
authorAndy Heninger <andy.heninger@gmail.com>
Wed, 11 Oct 2017 22:22:45 +0000 (22:22 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Wed, 11 Oct 2017 22:22:45 +0000 (22:22 +0000)
X-SVN-Rev: 40615

icu4c/source/common/locdispnames.cpp
icu4c/source/common/locdspnm.cpp
icu4c/source/common/ucurr.cpp
icu4c/source/i18n/ucol_sit.cpp

index 95750e440069498d3b97544e8d20dc2ba21fdf03..e38550274f94a317644c42d46ee91fa27e5c48ed 100644 (file)
@@ -821,6 +821,8 @@ uloc_getDisplayKeywordValue(   const char* locale,
     /* get the keyword value */
     keywordValue[0]=0;
     keywordValueLen = uloc_getKeywordValue(locale, keyword, keywordValue, capacity, status);
+    if (*status == U_STRING_NOT_TERMINATED_WARNING)
+      *status = U_BUFFER_OVERFLOW_ERROR;
 
     /* 
      * if the keyword is equal to currency .. then to get the display name 
index b034a278a427b97f7cde884568d083d96930d277..6ceb6cfc8bc6537edae4351069a88714b8c24ddd 100644 (file)
@@ -636,8 +636,9 @@ LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
     char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
     const char* key;
     while ((key = e->next((int32_t *)0, status)) != NULL) {
+      value[0] = 0;
       locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
-      if (U_FAILURE(status)) {
+      if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
         return result;
       }
       keyDisplayName(key, temp, TRUE);
index b7b00cbcebf29e4e03aa2329da889a6fbe705963..a772da9a2994172bee03d65342ba476f06570d15 100644 (file)
@@ -2230,6 +2230,7 @@ ucurr_countCurrencies(const char* locale,
         UErrorCode localStatus = U_ZERO_ERROR;
         char id[ULOC_FULLNAME_CAPACITY];
         uloc_getKeywordValue(locale, "currency", id, ULOC_FULLNAME_CAPACITY, &localStatus);
+
         // get country or country_variant in `id'
         /*uint32_t variantType =*/ idForLocale(locale, id, sizeof(id), ec);
 
index ad064f2ae422272af92eccc608ef8c76197688b2..43c1f5d6732888f0dd78b7270e2c149b3ff11bba 100644 (file)
@@ -465,8 +465,15 @@ ucol_prepareShortStringOpen( const char *definition,
     UResourceBundle *collElem = NULL;
     char keyBuffer[256];
     // if there is a keyword, we pick it up and try to get elements
-    if(!uloc_getKeywordValue(buffer, "collation", keyBuffer, 256, status)) {
-      // no keyword. we try to find the default setting, which will give us the keyword value
+    int32_t keyLen = uloc_getKeywordValue(buffer, "collation", keyBuffer, sizeof(keyBuffer), status);
+    // Treat too long a value as no keyword.
+    if(keyLen >= (int32_t)sizeof(keyBuffer)) {
+      keyLen = 0;
+      *status = U_ZERO_ERROR;
+    }
+    if(keyLen == 0) {
+      // no keyword
+      // we try to find the default setting, which will give us the keyword value
       UResourceBundle *defaultColl = ures_getByKeyWithFallback(collations, "default", NULL, status);
       if(U_SUCCESS(*status)) {
         int32_t defaultKeyLen = 0;