From c1475f4bbdf230bd2ed277ad97d667869291e58b Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 25 Sep 2023 14:24:57 -0700 Subject: [PATCH] ICU-22516 Return error while the style is invalid To avoid later unknown address in icu_74::UnicodeString::copyFrom --- icu4c/source/i18n/reldatefmt.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/icu4c/source/i18n/reldatefmt.cpp b/icu4c/source/i18n/reldatefmt.cpp index 7789b8cb2cf..ebdf6c9716e 100644 --- a/icu4c/source/i18n/reldatefmt.cpp +++ b/icu4c/source/i18n/reldatefmt.cpp @@ -805,6 +805,10 @@ RelativeDateTimeFormatter::RelativeDateTimeFormatter( if (U_FAILURE(status)) { return; } + if (styl < 0 || UDAT_STYLE_COUNT <= styl) { + status = U_ILLEGAL_ARGUMENT_ERROR; + return; + } if ((capitalizationContext >> 8) != UDISPCTX_TYPE_CAPITALIZATION) { status = U_ILLEGAL_ARGUMENT_ERROR; return;