Skip to content

Commit 0844d15

Browse files
committed
Fix appctx property lengths including the null terminator
1 parent ce53f9c commit 0844d15

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/mono/mono/metadata/appdomain.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,10 @@ mono_runtime_install_appctx_properties (void)
880880
for (int i = 0; i < n_appctx_props; ++i) {
881881
glong num_chars;
882882
combined_keys [i] = g_utf8_to_utf16 (appctx_keys [i], -1, NULL, &num_chars, NULL);
883-
combined_key_lengths [i] = GLONG_TO_UINT32 (num_chars);
883+
// HACK: items_written from g_utf8_to_utf16 includes the null terminator unless you pass an explicit length.
884+
combined_key_lengths [i] = GLONG_TO_UINT32 (num_chars ? num_chars - 1 : 0);
884885
combined_values [i] = g_utf8_to_utf16 (appctx_values [i], -1, NULL, &num_chars, NULL);
885-
combined_value_lengths [i] = GLONG_TO_UINT32 (num_chars);
886+
combined_value_lengths [i] = GLONG_TO_UINT32 (num_chars ? num_chars - 1 : 0);
886887
}
887888

888889
runtimeconfig_json_read_props (

0 commit comments

Comments
 (0)