]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/zonemeta.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / zonemeta.cpp
index be71a3b4fd9e38c7999a5fe8184de158723f2e80..84a965780291c9de458f4931c19f960ba18380ad 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 * Copyright (C) 2007-2014, International Business Machines Corporation and
@@ -15,7 +17,7 @@
 #include "unicode/ustring.h"
 #include "unicode/putil.h"
 #include "unicode/simpletz.h"
-
+#include "unicode/strenum.h"
 #include "umutex.h"
 #include "uvector.h"
 #include "cmemory.h"
@@ -26,8 +28,7 @@
 #include "uresimp.h"
 #include "uhash.h"
 #include "olsontz.h"
-
-#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
+#include "uinvchar.h"
 
 static UMutex gZoneMetaLock = U_MUTEX_INITIALIZER;
 
@@ -255,6 +256,12 @@ ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
     tzid.extract(utzid, ZID_KEY_MAX + 1, tmpStatus);
     U_ASSERT(tmpStatus == U_ZERO_ERROR);    // we checked the length of tzid already
 
+    if (!uprv_isInvariantUString(utzid, -1)) {
+        // All of known tz IDs are only containing ASCII invariant characters.
+        status = U_ILLEGAL_ARGUMENT_ERROR;
+        return NULL;
+    }
+
     // Check if it was already cached
     umtx_lock(&gZoneMetaLock);
     {
@@ -269,7 +276,7 @@ ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
     // If not, resolve CLDR canonical ID with resource data
     UBool isInputCanonical = FALSE;
     char id[ZID_KEY_MAX + 1];
-    tzid.extract(0, 0x7fffffff, id, LENGTHOF(id), US_INV);
+    tzid.extract(0, 0x7fffffff, id, UPRV_LENGTHOF(id), US_INV);
 
     // replace '/' with ':'
     char *p = id;