Skip to content

Commit 2f147fa

Browse files
authored
aot compiler: Bail out on too long native symbol names (#3663)
The old code was silently truncating long names.
1 parent a055e0b commit 2f147fa

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

core/iwasm/compilation/aot_llvm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3277,6 +3277,7 @@ static bool
32773277
insert_native_symbol(AOTCompContext *comp_ctx, const char *symbol, int32 idx)
32783278
{
32793279
AOTNativeSymbol *sym = wasm_runtime_malloc(sizeof(AOTNativeSymbol));
3280+
int ret;
32803281

32813282
if (!sym) {
32823283
aot_set_last_error("alloc native symbol failed.");
@@ -3285,7 +3286,11 @@ insert_native_symbol(AOTCompContext *comp_ctx, const char *symbol, int32 idx)
32853286

32863287
memset(sym, 0, sizeof(AOTNativeSymbol));
32873288
bh_assert(strlen(symbol) <= sizeof(sym->symbol));
3288-
snprintf(sym->symbol, sizeof(sym->symbol), "%s", symbol);
3289+
ret = snprintf(sym->symbol, sizeof(sym->symbol), "%s", symbol);
3290+
if (ret < 0 || ret + 1 > sizeof(sym->symbol)) {
3291+
aot_set_last_error_v("symbol name too long: %s", symbol);
3292+
return false;
3293+
}
32893294
sym->index = idx;
32903295

32913296
if (BH_LIST_ERROR == bh_list_insert(&comp_ctx->native_symbols, sym)) {

0 commit comments

Comments
 (0)