From 85600f263999b160cb2eedfa1dc389b540edcd76 Mon Sep 17 00:00:00 2001 From: Jeff Genovy <29107334+jefgen@users.noreply.github.com> Date: Mon, 21 Jan 2019 16:52:15 -0800 Subject: [PATCH] ICU-20370 Fix error checking in uloc_getLCID function. --- icu4c/source/common/uloc.cpp | 2 +- icu4c/source/test/cintltst/cloctst.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/icu4c/source/common/uloc.cpp b/icu4c/source/common/uloc.cpp index 3827457e982..6b65c626222 100644 --- a/icu4c/source/common/uloc.cpp +++ b/icu4c/source/common/uloc.cpp @@ -2191,7 +2191,7 @@ uloc_getLCID(const char* localeID) } uloc_getLanguage(localeID, langID, sizeof(langID), &status); - if (U_FAILURE(status)) { + if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) { return 0; } diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index 41f6d915e89..2268486a9f1 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -52,6 +52,7 @@ static void TestUnicodeDefines(void); static void TestIsRightToLeft(void); static void TestBadLocaleIDs(void); +static void TestBug20370(void); void PrintDataTable(); @@ -266,6 +267,7 @@ void addLocaleTest(TestNode** root) TESTCASE(TestToUnicodeLocaleType); TESTCASE(TestToLegacyType); TESTCASE(TestBadLocaleIDs); + TESTCASE(TestBug20370); } @@ -6498,3 +6500,13 @@ static void TestBadLocaleIDs() { } } } + +// Test case for ICU-20370. +// The issue shows as an Addresss Sanitizer failure. +static void TestBug20370() { + const char *localeID = "x-privatebutreallylongtagfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar"; + uint32_t lcid = uloc_getLCID(localeID); + if (lcid != 0) { + log_err("FAIL: Expected LCID value of 0 for invalid localeID input."); + } +} -- 2.40.0