]> granicus.if.org Git - icu/commitdiff
ICU-13277 Locale constructor buffer overflow.
authorAndy Heninger <andy.heninger@gmail.com>
Sat, 15 Jul 2017 00:22:20 +0000 (00:22 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Sat, 15 Jul 2017 00:22:20 +0000 (00:22 +0000)
X-SVN-Rev: 40267

icu4c/source/common/uloc.cpp
icu4c/source/test/intltest/loctest.cpp
icu4c/source/test/intltest/loctest.h

index 4d854bbcca320e185f989b6310e1c22ec732cfe0..9ca901607249c684a9272e2166862a027cfee7f2 100644 (file)
@@ -529,8 +529,10 @@ static const VariantMap VARIANT_MAP[] = {
 #define _hasBCP47Extension(id) (id && uprv_strstr(id, "@") == NULL && getShortestSubtagLength(localeID) == 1)
 /* Converts the BCP47 id to Unicode id. Does nothing to id if conversion fails */
 #define _ConvertBCP47(finalID, id, buffer, length,err) \
-        if (uloc_forLanguageTag(id, buffer, length, NULL, err) <= 0 || U_FAILURE(*err)) { \
+        if (uloc_forLanguageTag(id, buffer, length, NULL, err) <= 0 ||  \
+                U_FAILURE(*err) || *err == U_STRING_NOT_TERMINATED_WARNING) { \
             finalID=id; \
+            if (*err == U_STRING_NOT_TERMINATED_WARNING) { *err = U_BUFFER_OVERFLOW_ERROR; } \
         } else { \
             finalID=buffer; \
         }
index 5bb2dc24dd2d4ca82af7a1eb654953f9312bbc11..866fe9adcd95fd51efc0bafab1fb1de5205b09c6 100644 (file)
@@ -13,6 +13,7 @@
 #include "unicode/dtfmtsym.h"
 #include "unicode/brkiter.h"
 #include "unicode/coll.h"
+#include "charstr.h"
 #include "cmemory.h"
 #include "cstring.h"
 #include <stdio.h>
@@ -228,6 +229,7 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
     TESTCASE_AUTO(TestCurrencyByDate);
     TESTCASE_AUTO(TestGetVariantWithKeywords);
     TESTCASE_AUTO(TestIsRightToLeft);
+    TESTCASE_AUTO(TestBug13277);
     TESTCASE_AUTO_END;
 }
 
@@ -2711,3 +2713,21 @@ void LocaleTest::TestBug11421() {
         }
     }
 }
+
+//  TestBug13277. The failure manifests as valgrind errors.
+//                See the trac ticket for details.
+//                
+
+void LocaleTest::TestBug13277() {
+    UErrorCode status = U_ZERO_ERROR;
+    CharString name("en-us-x-foo", -1, status);
+    while (name.length() < 152) {
+        name.append("-x-foo", -1, status);
+    }
+
+    while (name.length() < 160) {
+        name.append('z', status);
+        Locale loc(name.data(), nullptr, nullptr, nullptr);
+    }
+}
+
index ad4821707c3dc771aa5ea5c450b699df9a0ee46f..270f427952e51674e6b4acb320533fefa1fd1ee2 100644 (file)
@@ -105,6 +105,7 @@ public:
     void TestGetVariantWithKeywords(void);
     void TestIsRightToLeft();
     void TestBug11421();
+    void TestBug13277();
 
 private:
     void _checklocs(const char* label,