File icu-CVE-2025-5222-shim02_80a6684.patch of Package icu

From 80a6684a7b448f4058a3475dc958e65d98cf7b52 Mon Sep 17 00:00:00 2001
From: Andy Heninger <andy.heninger@gmail.com>
Date: Thu, 20 Aug 2015 00:55:03 +0000
Subject: [PATCH] ICU-11794 change error handling of
 CharString::appendInvariantChars()

X-SVN-Rev: 37790
---
 icu4c/source/common/charstr.cpp        | 10 +++++++++-
 icu4c/source/test/intltest/strtest.cpp | 12 +++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

--- a/source/common/charstr.cpp
+++ b/source/common/charstr.cpp
@@ -16,6 +16,7 @@
 #include "charstr.h"
 #include "cmemory.h"
 #include "cstring.h"
+#include "uinvchar.h"
 
 U_NAMESPACE_BEGIN
 
@@ -101,6 +102,13 @@
 }
 
 CharString &CharString::appendInvariantChars(const UnicodeString &s, UErrorCode &errorCode) {
+    if(U_FAILURE(errorCode)) {
+        return *this;
+    }
+    if (!uprv_isInvariantUString(s.getBuffer(), s.length())) {
+        errorCode = U_INVARIANT_CONVERSION_ERROR;
+        return *this;
+    }
     if(ensureCapacity(len+s.length()+1, 0, errorCode)) {
         len+=s.extract(0, 0x7fffffff, buffer.getAlias()+len, buffer.getCapacity()-len, US_INV);
     }

--- a/source/test/intltest/strtest.cpp
+++ b/source/test/intltest/strtest.cpp
@@ -521,4 +521,14 @@
     if (0 != strcmp(expected, chStr.data()) || (int32_t)strlen(expected) != chStr.length()) {
         errln("CharString.getAppendBuffer().append(**) failed.");
     }
+
+    UErrorCode ec = U_ZERO_ERROR;
+    chStr.clear();
+    chStr.appendInvariantChars(UnicodeString("The '@' character is not invariant."), ec);
+    if (ec != U_INVARIANT_CONVERSION_ERROR) {
+        errln("%s:%d expected U_INVARIANT_CONVERSION_ERROR, got %s", __FILE__, __LINE__, u_errorName(ec));
+    }
+    if (chStr.length() != 0) {
+        errln("%s:%d expected length() = 0, got %d", __FILE__, __LINE__, chStr.length());
+    }
 }
openSUSE Build Service is sponsored by