Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ static bool
check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length < buf || buf + length > buf_end) {
if ((uintptr_t)buf + length < (uintptr_t)buf
|| (uintptr_t)buf + length > (uintptr_t)buf_end) {
set_error_buf(error_buf, error_buf_size, "unexpect end");
return false;
}
Expand Down
13 changes: 6 additions & 7 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ align_ptr(const uint8 *p, uint32 b)
return (uint8 *)((v + m) & ~m);
}

#define CHECK_BUF(buf, buf_end, length) \
do { \
if (buf + length < buf || buf + length > buf_end) \
return false; \
#define CHECK_BUF(buf, buf_end, length) \
do { \
if ((uintptr_t)buf + length < (uintptr_t)buf \
|| (uintptr_t)buf + length > (uintptr_t)buf_end) \
return false; \
} while (0)

#define read_uint16(p, p_end, res) \
Expand Down Expand Up @@ -347,9 +348,7 @@ wasm_runtime_is_xip_file(const uint8 *buf, uint32 size)
if (section_type == AOT_SECTION_TYPE_TARGET_INFO) {
p += 4;
read_uint16(p, p_end, e_type);
if (e_type == E_TYPE_XIP) {
return true;
}
return (e_type == E_TYPE_XIP) ? true : false;
}
else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) {
return false;
Expand Down
6 changes: 4 additions & 2 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ static bool
check_buf(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length < buf || buf + length > buf_end) {
if ((uintptr_t)buf + length < (uintptr_t)buf
|| (uintptr_t)buf + length > (uintptr_t)buf_end) {
set_error_buf(error_buf, error_buf_size,
"unexpected end of section or function");
return false;
Expand All @@ -59,7 +60,8 @@ static bool
check_buf1(const uint8 *buf, const uint8 *buf_end, uint32 length,
char *error_buf, uint32 error_buf_size)
{
if (buf + length < buf || buf + length > buf_end) {
if ((uintptr_t)buf + length < (uintptr_t)buf
|| (uintptr_t)buf + length > (uintptr_t)buf_end) {
set_error_buf(error_buf, error_buf_size, "unexpected end");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ align_ptr(const uint8 *p, uint32 b)
#define AOT_SECTION_TYPE_SIGANATURE 6
#define E_TYPE_XIP 4

#define CHECK_BUF(buf, buf_end, length) \
do { \
if (buf + length < buf || buf + length > buf_end) \
return false; \
#define CHECK_BUF(buf, buf_end, length) \
do { \
if ((uintptr_t)buf + length < (uintptr_t)buf \
|| (uintptr_t)buf + length > (uintptr_t)buf_end) \
return false; \
} while (0)

#define read_uint16(p, p_end, res) \
Expand Down Expand Up @@ -162,6 +163,7 @@ is_xip_file(const uint8 *buf, uint32 size)

if (get_package_type(buf, size) != Wasm_Module_AoT)
return false;

CHECK_BUF(p, p_end, 8);
p += 8;
while (p < p_end) {
Expand All @@ -172,15 +174,14 @@ is_xip_file(const uint8 *buf, uint32 size)
if (section_type == AOT_SECTION_TYPE_TARGET_INFO) {
p += 4;
read_uint16(p, p_end, e_type);
if (e_type == E_TYPE_XIP) {
return true;
}
return (e_type == E_TYPE_XIP) ? true : false;
}
else if (section_type >= AOT_SECTION_TYPE_SIGANATURE) {
return false;
}
p += section_size;
}

return false;
}

Expand Down