Skip to content

Commit 9f64340

Browse files
authored
1 parent ab97d54 commit 9f64340

File tree

9 files changed

+20
-17
lines changed

9 files changed

+20
-17
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,8 +3134,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode,
31343134
p += 8;
31353135
while (p < p_end) {
31363136
read_uint32(p, p_end, section_type);
3137-
if (section_type <= AOT_SECTION_TYPE_SIGANATURE
3138-
|| section_type == AOT_SECTION_TYPE_TARGET_INFO) {
3137+
if (section_type <= AOT_SECTION_TYPE_SIGANATURE) {
31393138
read_uint32(p, p_end, section_size);
31403139
CHECK_BUF(p, p_end, section_size);
31413140
if (section_type == AOT_SECTION_TYPE_TARGET_INFO) {
@@ -3150,7 +3149,7 @@ resolve_execute_mode(const uint8 *buf, uint32 size, bool *p_mode,
31503149
break;
31513150
}
31523151
}
3153-
else if (section_type > AOT_SECTION_TYPE_SIGANATURE) {
3152+
else { /* section_type > AOT_SECTION_TYPE_SIGANATURE */
31543153
set_error_buf(error_buf, error_buf_size,
31553154
"resolve execute mode failed");
31563155
break;

core/iwasm/common/wasm_c_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ wasm_module_new(wasm_store_t *store, const wasm_byte_vec_t *binary)
22942294
(uint8 *)module_ex->binary->data, (uint32)module_ex->binary->size,
22952295
error_buf, (uint32)sizeof(error_buf));
22962296
if (!(module_ex->module_comm_rt)) {
2297-
LOG_ERROR(error_buf);
2297+
LOG_ERROR("%s", error_buf);
22982298
goto free_vec;
22992299
}
23002300

@@ -2367,7 +2367,7 @@ wasm_module_validate(wasm_store_t *store, const wasm_byte_vec_t *binary)
23672367
}
23682368
else {
23692369
ret = false;
2370-
LOG_VERBOSE(error_buf);
2370+
LOG_VERBOSE("%s", error_buf);
23712371
}
23722372

23732373
return ret;
@@ -3359,7 +3359,7 @@ wasm_func_call(const wasm_func_t *func, const wasm_val_vec_t *params,
33593359
wasm_runtime_set_exception(func->inst_comm_rt, NULL);
33603360
if (!wasm_runtime_call_wasm(exec_env, func_comm_rt, argc, argv)) {
33613361
if (wasm_runtime_get_exception(func->inst_comm_rt)) {
3362-
LOG_DEBUG(wasm_runtime_get_exception(func->inst_comm_rt));
3362+
LOG_DEBUG("%s", wasm_runtime_get_exception(func->inst_comm_rt));
33633363
goto failed;
33643364
}
33653365
}
@@ -5044,7 +5044,7 @@ wasm_instance_new_with_args(wasm_store_t *store, const wasm_module_t *module,
50445044
*trap = wasm_trap_new(store, &message);
50455045
wasm_byte_vec_delete(&message);
50465046
}
5047-
LOG_DEBUG(error_buf);
5047+
LOG_DEBUG("%s", error_buf);
50485048
wasm_instance_delete_internal(instance);
50495049
return NULL;
50505050
}

core/iwasm/common/wasm_native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ wasm_native_resolve_symbol(const char *module_name, const char *field_name,
194194
{
195195
NativeSymbolsNode *node, *node_next;
196196
const char *signature = NULL;
197-
void *func_ptr = NULL, *attachment;
197+
void *func_ptr = NULL, *attachment = NULL;
198198

199199
node = g_native_symbols_list;
200200
while (node) {

core/iwasm/common/wasm_runtime_common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,8 @@ copy_string_array(const char *array[], uint32 array_size, char **buf_ptr,
29052905
/* We add +1 to generate null-terminated array of strings */
29062906
total_size = sizeof(char *) * ((uint64)array_size + 1);
29072907
if (total_size >= UINT32_MAX
2908-
|| (total_size > 0 && !(list = wasm_runtime_malloc((uint32)total_size)))
2908+
/* total_size must be larger than 0, don' check it again */
2909+
|| !(list = wasm_runtime_malloc((uint32)total_size))
29092910
|| buf_size >= UINT32_MAX
29102911
|| (buf_size > 0 && !(buf = wasm_runtime_malloc((uint32)buf_size)))) {
29112912

core/iwasm/interpreter/wasm_loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ check_utf8_str(const uint8 *str, uint32 len)
327327
return false;
328328
}
329329
}
330-
else if (chr >= 0xE1 && chr <= 0xEF) {
330+
else { /* chr >= 0xE1 && chr <= 0xEF */
331331
if (p[1] < 0x80 || p[1] > 0xBF || p[2] < 0x80 || p[2] > 0xBF) {
332332
return false;
333333
}
@@ -341,13 +341,13 @@ check_utf8_str(const uint8 *str, uint32 len)
341341
return false;
342342
}
343343
}
344-
else if (chr >= 0xF1 && chr <= 0xF3) {
344+
else if (chr <= 0xF3) { /* and also chr >= 0xF1 */
345345
if (p[1] < 0x80 || p[1] > 0xBF || p[2] < 0x80 || p[2] > 0xBF
346346
|| p[3] < 0x80 || p[3] > 0xBF) {
347347
return false;
348348
}
349349
}
350-
else if (chr == 0xF4) {
350+
else { /* chr == 0xF4 */
351351
if (p[1] < 0x80 || p[1] > 0x8F || p[2] < 0x80 || p[2] > 0xBF
352352
|| p[3] < 0x80 || p[3] > 0xBF) {
353353
return false;

core/iwasm/libraries/libc-wasi/libc_wasi_wrapper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,8 @@ copy_buffer_to_iovec_app(wasm_module_inst_t module_inst, uint8 *buf_begin,
20132013
}
20142014

20152015
if (buf >= buf_begin + buf_size
2016-
|| buf + data->buf_len < buf /* integer overflow */
2016+
/* integer overflow */
2017+
|| data->buf_len > UINTPTR_MAX - (uintptr_t)buf
20172018
|| buf + data->buf_len > buf_begin + buf_size
20182019
|| size_to_copy == 0) {
20192020
break;

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ wasm_cluster_dup_c_api_imports(WASMModuleInstanceCommon *module_inst_dst,
787787
{
788788
/* workaround about passing instantiate-linking information */
789789
CApiFuncImport **new_c_api_func_imports = NULL;
790-
CApiFuncImport *c_api_func_imports;
790+
CApiFuncImport *c_api_func_imports = NULL;
791791
uint32 import_func_count = 0;
792792
uint32 size_in_bytes = 0;
793793

core/shared/platform/common/posix/posix_socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s)
884884
int
885885
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
886886
{
887-
socklen_t opt_len = sizeof(ttl_s);
887+
socklen_t opt_len = sizeof(*ttl_s);
888888
if (getsockopt(socket, IPPROTO_IP, IP_TTL, ttl_s, &opt_len) != 0) {
889889
return BHT_ERROR;
890890
}
@@ -906,7 +906,7 @@ os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s)
906906
int
907907
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
908908
{
909-
socklen_t opt_len = sizeof(ttl_s);
909+
socklen_t opt_len = sizeof(*ttl_s);
910910
if (getsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, &opt_len)
911911
!= 0) {
912912
return BHT_ERROR;

core/shared/utils/bh_hashmap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ bh_hash_map_create(uint32 size, bool use_lock, HashFunc hash_func,
5151
+ sizeof(HashMapElem *) * (uint64)size
5252
+ (use_lock ? sizeof(korp_mutex) : 0);
5353

54-
if (total_size >= UINT32_MAX || !(map = BH_MALLOC((uint32)total_size))) {
54+
/* size <= HASH_MAP_MAX_SIZE, so total_size won't be larger than
55+
UINT32_MAX, no need to check integer overflow */
56+
if (!(map = BH_MALLOC((uint32)total_size))) {
5557
LOG_ERROR("HashMap create failed: alloc memory failed.\n");
5658
return NULL;
5759
}

0 commit comments

Comments
 (0)