From 0844d155d5560c5c37936dd6102196b4401941c0 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 24 Apr 2024 14:20:29 -0700 Subject: [PATCH] Fix appctx property lengths including the null terminator --- src/mono/mono/metadata/appdomain.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/appdomain.c b/src/mono/mono/metadata/appdomain.c index fc12cc9a21675c..f0a7789108d552 100644 --- a/src/mono/mono/metadata/appdomain.c +++ b/src/mono/mono/metadata/appdomain.c @@ -880,9 +880,10 @@ mono_runtime_install_appctx_properties (void) for (int i = 0; i < n_appctx_props; ++i) { glong num_chars; combined_keys [i] = g_utf8_to_utf16 (appctx_keys [i], -1, NULL, &num_chars, NULL); - combined_key_lengths [i] = GLONG_TO_UINT32 (num_chars); + // HACK: items_written from g_utf8_to_utf16 includes the null terminator unless you pass an explicit length. + combined_key_lengths [i] = GLONG_TO_UINT32 (num_chars ? num_chars - 1 : 0); combined_values [i] = g_utf8_to_utf16 (appctx_values [i], -1, NULL, &num_chars, NULL); - combined_value_lengths [i] = GLONG_TO_UINT32 (num_chars); + combined_value_lengths [i] = GLONG_TO_UINT32 (num_chars ? num_chars - 1 : 0); } runtimeconfig_json_read_props (