@@ -99,7 +99,11 @@ static const char *
99
99
runtimeconfig_json_get_buffer (MonovmRuntimeConfigArguments * arg , MonoFileMap * * file_map , gpointer * buf_handle );
100
100
101
101
static void
102
- runtimeconfig_json_read_props (const char * ptr , const char * * endp , int nprops , gunichar2 * * dest_keys , gunichar2 * * dest_values );
102
+ runtimeconfig_json_read_props (
103
+ const char * ptr , const char * * endp , int nprops ,
104
+ gunichar2 * * dest_keys , guint32 * dest_key_lengths ,
105
+ gunichar2 * * dest_values , guint32 * dest_value_lengths
106
+ );
103
107
104
108
static MonoLoadFunc load_function = NULL ;
105
109
@@ -846,17 +850,19 @@ void
846
850
mono_runtime_install_appctx_properties (void )
847
851
{
848
852
ERROR_DECL (error );
849
- gpointer args [3 ];
853
+ gpointer args [5 ];
850
854
int n_runtimeconfig_json_props = 0 ;
851
855
int n_combined_props ;
852
856
gunichar2 * * combined_keys ;
853
857
gunichar2 * * combined_values ;
858
+ guint32 * combined_key_lengths ;
859
+ guint32 * combined_value_lengths ;
854
860
MonoFileMap * runtimeconfig_json_map = NULL ;
855
861
gpointer runtimeconfig_json_map_handle = NULL ;
856
862
const char * buffer_start = runtimeconfig_json_get_buffer (runtime_config_arg , & runtimeconfig_json_map , & runtimeconfig_json_map_handle );
857
863
const char * buffer = buffer_start ;
858
864
859
- MonoMethod * setup = mono_class_get_method_from_name_checked (mono_class_get_appctx_class (), "Setup" , 3 , 0 , error );
865
+ MonoMethod * setup = mono_class_get_method_from_name_checked (mono_class_get_appctx_class (), "Setup" , 5 , 0 , error );
860
866
g_assert (setup );
861
867
862
868
// FIXME: TRUSTED_PLATFORM_ASSEMBLIES is very large
@@ -867,19 +873,31 @@ mono_runtime_install_appctx_properties (void)
867
873
868
874
n_combined_props = n_appctx_props + n_runtimeconfig_json_props ;
869
875
combined_keys = g_new0 (gunichar2 * , n_combined_props );
876
+ combined_key_lengths = g_new0 (guint32 , n_combined_props );
870
877
combined_values = g_new0 (gunichar2 * , n_combined_props );
878
+ combined_value_lengths = g_new0 (guint32 , n_combined_props );
871
879
872
880
for (int i = 0 ; i < n_appctx_props ; ++ i ) {
873
- combined_keys [i ] = g_utf8_to_utf16 (appctx_keys [i ], -1 , NULL , NULL , NULL );
874
- combined_values [i ] = g_utf8_to_utf16 (appctx_values [i ], -1 , NULL , NULL , NULL );
881
+ glong num_chars ;
882
+ combined_keys [i ] = g_utf8_to_utf16 (appctx_keys [i ], -1 , NULL , & num_chars , NULL );
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 );
885
+ combined_values [i ] = g_utf8_to_utf16 (appctx_values [i ], -1 , NULL , & num_chars , NULL );
886
+ combined_value_lengths [i ] = GLONG_TO_UINT32 (num_chars ? num_chars - 1 : 0 );
875
887
}
876
888
877
- runtimeconfig_json_read_props (buffer , & buffer , n_runtimeconfig_json_props , combined_keys + n_appctx_props , combined_values + n_appctx_props );
889
+ runtimeconfig_json_read_props (
890
+ buffer , & buffer , n_runtimeconfig_json_props ,
891
+ combined_keys + n_appctx_props , combined_key_lengths + n_appctx_props ,
892
+ combined_values + n_appctx_props , combined_value_lengths + n_appctx_props
893
+ );
878
894
879
- /* internal static unsafe void Setup(char** pNames, char** pValues, int count) */
895
+ /* internal static unsafe void Setup(char** pNames, uint* pNameLengths, char** pValues, uint* pValueLengths , int count) */
880
896
args [0 ] = combined_keys ;
881
- args [1 ] = combined_values ;
882
- args [2 ] = & n_combined_props ;
897
+ args [1 ] = combined_key_lengths ;
898
+ args [2 ] = combined_values ;
899
+ args [3 ] = combined_value_lengths ;
900
+ args [4 ] = & n_combined_props ;
883
901
884
902
mono_runtime_invoke_checked (setup , NULL , args , error );
885
903
mono_error_assert_ok (error );
@@ -900,6 +918,8 @@ mono_runtime_install_appctx_properties (void)
900
918
}
901
919
g_free (combined_keys );
902
920
g_free (combined_values );
921
+ g_free (combined_key_lengths );
922
+ g_free (combined_value_lengths );
903
923
for (int i = 0 ; i < n_appctx_props ; ++ i ) {
904
924
g_free (appctx_keys [i ]);
905
925
g_free (appctx_values [i ]);
@@ -949,17 +969,24 @@ runtimeconfig_json_get_buffer (MonovmRuntimeConfigArguments *arg, MonoFileMap **
949
969
}
950
970
951
971
static void
952
- runtimeconfig_json_read_props (const char * ptr , const char * * endp , int nprops , gunichar2 * * dest_keys , gunichar2 * * dest_values )
972
+ runtimeconfig_json_read_props (
973
+ const char * ptr , const char * * endp , int nprops ,
974
+ gunichar2 * * dest_keys , guint32 * dest_key_lengths ,
975
+ gunichar2 * * dest_values , guint32 * dest_value_lengths
976
+ )
953
977
{
954
978
for (int i = 0 ; i < nprops ; ++ i ) {
955
979
int str_len ;
980
+ glong chars_written ;
956
981
957
982
str_len = mono_metadata_decode_value (ptr , & ptr );
958
- dest_keys [i ] = g_utf8_to_utf16 (ptr , str_len , NULL , NULL , NULL );
983
+ dest_keys [i ] = g_utf8_to_utf16 (ptr , str_len , NULL , & chars_written , NULL );
984
+ dest_key_lengths [i ] = GLONG_TO_UINT32 (chars_written );
959
985
ptr += str_len ;
960
986
961
987
str_len = mono_metadata_decode_value (ptr , & ptr );
962
- dest_values [i ] = g_utf8_to_utf16 (ptr , str_len , NULL , NULL , NULL );
988
+ dest_values [i ] = g_utf8_to_utf16 (ptr , str_len , NULL , & chars_written , NULL );
989
+ dest_value_lengths [i ] = GLONG_TO_UINT32 (chars_written );
963
990
ptr += str_len ;
964
991
}
965
992
0 commit comments