Skip to content

Commit

Permalink
Check arguments before calling bh_hash_map_find (bytecodealliance#3055)
Browse files Browse the repository at this point in the history
Check whether the arguments are NULL before calling bh_hash_map_find,
or lots of "HashMap find elem failed: map or key is NULL" warnings may
be dumped. Reported in bytecodealliance#3053.
  • Loading branch information
wenyongh authored Jan 19, 2024
1 parent 6a1cd7b commit 94f9612
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions core/iwasm/common/wasm_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ acquire_wait_info(void *address, AtomicWaitNode *wait_node)
AtomicWaitInfo *wait_info = NULL;
bh_list_status ret;

if (address)
wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address);
bh_assert(address != NULL);

wait_info = (AtomicWaitInfo *)bh_hash_map_find(wait_map, address);

if (!wait_node) {
return wait_info;
Expand Down
14 changes: 12 additions & 2 deletions core/iwasm/libraries/lib-pthread/lib_pthread_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ get_thread_info(wasm_exec_env_t exec_env, uint32 handle)
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
ClusterInfoNode *info = get_cluster_info(cluster);

if (!info) {
if (!info || !handle) {
return NULL;
}

Expand Down Expand Up @@ -1144,6 +1144,10 @@ sem_open_wrapper(wasm_exec_env_t exec_env, const char *name, int32 oflags,
* For Unix like system, it's dedicated for multiple processes.
*/

if (!name) { /* avoid passing NULL to bh_hash_map_find and os_sem_open */
return -1;
}

if ((info_node = bh_hash_map_find(sem_info_map, (void *)name))) {
return info_node->handle;
}
Expand Down Expand Up @@ -1276,7 +1280,13 @@ sem_unlink_wrapper(wasm_exec_env_t exec_env, const char *name)
(void)exec_env;
int32 ret_val;

ThreadInfoNode *info_node = bh_hash_map_find(sem_info_map, (void *)name);
ThreadInfoNode *info_node;

if (!name) { /* avoid passing NULL to bh_hash_map_find */
return -1;
}

info_node = bh_hash_map_find(sem_info_map, (void *)name);
if (!info_node || info_node->type != T_SEM)
return -1;

Expand Down

0 comments on commit 94f9612

Please sign in to comment.