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 (