Skip to content

Commit ad76be3

Browse files
authored
Merge pull request #828 from yamt/toywasm-functype
wasm_toywasm.c: validate the type of callback functions
2 parents 0f04103 + 5d6964e commit ad76be3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

runtimes/native/src/backend/wasm_toywasm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ static uint32_t find_func(const struct module *m, const char *name_cstr,
324324
ret);
325325
exit(1);
326326
}
327+
/*
328+
* note: we don't use exported functions with parameters or results.
329+
*/
330+
const struct functype *ft = module_functype(m, idx);
331+
if (ft->parameter.ntypes != 0 || ft->result.ntypes != 0) {
332+
if (!require) {
333+
return (uint32_t)-1;
334+
}
335+
fprintf(stderr, "exported function (%s) has an unexpected type\n",
336+
name_cstr);
337+
exit(1);
338+
}
327339
return idx;
328340
}
329341

0 commit comments

Comments
 (0)