From 78cb9ef40bbe47aef758651025d995ef67f41ccc Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Tue, 19 May 2020 19:10:45 -0700 Subject: [PATCH 1/2] Move app local string length validation to native shim --- .../src/System/Globalization/GlobalizationMode.cs | 11 ----------- .../Unix/System.Globalization.Native/pal_icushim.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs index dd460b178945f6..2c173244bb83de 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs @@ -59,12 +59,6 @@ private static void LoadAppLocalIcu(string icuSuffixAndVersion, bool suffixWithS if (indexOfSeparator >= 0) { icuSuffix = icuSuffixAndVersion.AsSpan().Slice(0, indexOfSeparator); - - if (icuSuffix.Length > 35) - { - Environment.FailFast($"The resolved \"{icuSuffix.ToString()}\" suffix from System.Globalization.AppLocalIcu switch has to be < 20 chars long."); - } - version = icuSuffixAndVersion.AsSpan().Slice(icuSuffix.Length + 1); } else @@ -72,11 +66,6 @@ private static void LoadAppLocalIcu(string icuSuffixAndVersion, bool suffixWithS version = icuSuffixAndVersion; } - if (version.Length > 33) - { - Environment.FailFast($"The resolved version \"{version.ToString()}\" from System.Globalization.AppLocalIcu switch has to be < 33 chars long."); - } - if (suffixWithSeparator) { icuSuffix = string.Concat(icuSuffix, "."); diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c index 093188b964a0e9..e4fafb7c2bbcb5 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c @@ -432,10 +432,23 @@ void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* char symbolVersion[MaxICUVersionStringWithSuffixLength + 1]=""; char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; + if (strlen(version) > MaxICUVersionStringLength) + { + fprintf(stderr, "The resolved version \"%s\" from System.Globalization.AppLocalIcu switch has to be < %d chars long.\n", version, MaxICUVersionStringLength); + abort(); + } + sscanf(version, "%d.%d.%d", &major, &minor, &build); if (suffix != NULL) { + int suffixAllowedSize = SYMBOL_CUSTOM_SUFFIX_SIZE - 2; // SYMBOL_CUSTOM_SUFFIX_SIZE considers `_` and `\0`. + if (strlen(suffix) > suffixAllowedSize) + { + fprintf(stderr, "The resolved suffix \"%s\" from System.Globalization.AppLocalIcu switch has to be < %d chars long.\n", suffix, suffixAllowedSize); + abort(); + } + assert(strlen(suffix) + 1 <= SYMBOL_CUSTOM_SUFFIX_SIZE); #if defined(TARGET_WINDOWS) From 1d16730bafab6473f9c64cde3c291895c35e017d Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Wed, 20 May 2020 16:36:39 -0700 Subject: [PATCH 2/2] Fix build --- .../Native/Unix/System.Globalization.Native/pal_icushim.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c index e4fafb7c2bbcb5..7fa6dd6fd8ac16 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim.c @@ -432,9 +432,9 @@ void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* char symbolVersion[MaxICUVersionStringWithSuffixLength + 1]=""; char symbolSuffix[SYMBOL_CUSTOM_SUFFIX_SIZE]=""; - if (strlen(version) > MaxICUVersionStringLength) + if (strlen(version) > (size_t)MaxICUVersionStringLength) { - fprintf(stderr, "The resolved version \"%s\" from System.Globalization.AppLocalIcu switch has to be < %d chars long.\n", version, MaxICUVersionStringLength); + fprintf(stderr, "The resolved version \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", version, (size_t)MaxICUVersionStringLength); abort(); } @@ -442,10 +442,10 @@ void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* if (suffix != NULL) { - int suffixAllowedSize = SYMBOL_CUSTOM_SUFFIX_SIZE - 2; // SYMBOL_CUSTOM_SUFFIX_SIZE considers `_` and `\0`. + size_t suffixAllowedSize = SYMBOL_CUSTOM_SUFFIX_SIZE - 2; // SYMBOL_CUSTOM_SUFFIX_SIZE considers `_` and `\0`. if (strlen(suffix) > suffixAllowedSize) { - fprintf(stderr, "The resolved suffix \"%s\" from System.Globalization.AppLocalIcu switch has to be < %d chars long.\n", suffix, suffixAllowedSize); + fprintf(stderr, "The resolved suffix \"%s\" from System.Globalization.AppLocalIcu switch has to be < %zu chars long.\n", suffix, suffixAllowedSize); abort(); }