@@ -4485,14 +4485,15 @@ static void *nif_code_all_available_fold(void *accum, const void *section_ptr, u
4485
4485
4486
4486
struct CodeAllAvailableAcc * acc = (struct CodeAllAvailableAcc * ) accum ;
4487
4487
size_t section_name_len = strlen (section_name );
4488
- if (section_name_len < 260 ) {
4489
- if (memcmp (".beam" , section_name + section_name_len - 5 , 5 ) == 0 ) {
4488
+ if (flags & BEAM_CODE_FLAG && section_name_len > 5 && section_name_len < 260 ) {
4489
+ size_t module_name_len = section_name_len - 5 ;
4490
+ if (memcmp (".beam" , section_name + module_name_len , 5 ) == 0 ) {
4490
4491
bool loaded ;
4491
4492
if (acc -> avmpack_data -> in_use ) {
4492
4493
// Check if module is loaded
4493
- char atom_str [section_name_len - 5 ];
4494
- atom_str [0 ] = section_name_len - 5 ;
4495
- memcpy (atom_str + 1 , section_name , atom_str [ 0 ] );
4494
+ char atom_str [module_name_len + 1 ];
4495
+ atom_str [0 ] = module_name_len ;
4496
+ memcpy (atom_str + 1 , section_name , module_name_len );
4496
4497
Module * loaded_module = globalcontext_get_module (acc -> ctx -> global , (AtomString ) & atom_str );
4497
4498
loaded = loaded_module != NULL ;
4498
4499
} else {
@@ -4502,7 +4503,7 @@ static void *nif_code_all_available_fold(void *accum, const void *section_ptr, u
4502
4503
acc -> acc_count ++ ;
4503
4504
if (!term_is_invalid_term (acc -> result )) {
4504
4505
term module_tuple = term_alloc_tuple (3 , & acc -> ctx -> heap );
4505
- term_put_tuple_element (module_tuple , 0 , term_from_const_binary (section_name , section_name_len - 5 , & acc -> ctx -> heap , acc -> ctx -> global ));
4506
+ term_put_tuple_element (module_tuple , 0 , term_from_const_binary (section_name , module_name_len , & acc -> ctx -> heap , acc -> ctx -> global ));
4506
4507
term_put_tuple_element (module_tuple , 1 , UNDEFINED_ATOM );
4507
4508
term_put_tuple_element (module_tuple , 2 , FALSE_ATOM );
4508
4509
acc -> result = term_list_prepend (module_tuple , acc -> result , & acc -> ctx -> heap );
0 commit comments