From: Eli Kobrin <kobrineli@ispras.ru>
Date: Thu, 3 Nov 2022 15:25:33 +0000 (+0300)
Subject: ICU-22198 Fix stack buffer overflow.
X-Git-Tag: cldr/2022-12-02~8
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b7ef3d9088c130cf0ef8973b30ceb39a40b605a;p=icu

ICU-22198 Fix stack buffer overflow.
---

diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp
index 17c0177a05c..81fb90e1384 100644
--- a/icu4c/source/common/uresbund.cpp
+++ b/icu4c/source/common/uresbund.cpp
@@ -202,7 +202,8 @@ typedef enum UResOpenType UResOpenType;
  */
 static bool getParentLocaleID(char *name, const char *origName, UResOpenType openType) {
     // early out if the locale ID has a variant code or ends with _
-    if (name[uprv_strlen(name) - 1] == '_' || hasVariant(name)) {
+    size_t nameLen = uprv_strlen(name);
+    if (!nameLen || name[nameLen - 1] == '_' || hasVariant(name)) {
         return chopLocale(name);
     }