|
13 | 13 |
|
14 | 14 | using namespace std; |
15 | 15 |
|
16 | | -extern "C" WASMModuleCommon * |
17 | | -wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf, |
18 | | - uint32 error_buf_size); |
19 | | - |
20 | | -extern "C" WASMModuleInstanceCommon * |
21 | | -wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size, |
22 | | - uint32 heap_size, char *error_buf, |
23 | | - uint32 error_buf_size); |
24 | | - |
25 | 16 | extern "C" int |
26 | 17 | LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
27 | 18 | { |
28 | 19 | /* libfuzzer don't allow us to modify the given Data, so we copy the data |
29 | 20 | * here */ |
30 | 21 | std::vector<uint8_t> myData(Data, Data + Size); |
| 22 | + |
31 | 23 | /* init runtime environment */ |
32 | 24 | wasm_runtime_init(); |
| 25 | + |
| 26 | + char error_buf[128] = { 0 }; |
33 | 27 | wasm_module_t module = |
34 | | - wasm_runtime_load((uint8_t *)myData.data(), Size, nullptr, 0); |
35 | | - if (module) { |
| 28 | + wasm_runtime_load((uint8_t *)myData.data(), Size, error_buf, 120); |
| 29 | + if (!module) { |
| 30 | + std::cout << "[LOADING] " << error_buf << std::endl; |
| 31 | + wasm_runtime_destroy(); |
| 32 | + /* return SUCCESS because the failure has been handled */ |
| 33 | + return 0; |
| 34 | + } |
| 35 | + |
| 36 | + wasm_module_inst_t inst = wasm_runtime_instantiate( |
| 37 | + module, 8 * 1024 * 1024, 16 * 1024 * 1024, error_buf, 120); |
| 38 | + if (!inst) { |
| 39 | + std::cout << "[INSTANTIATE] " << error_buf << std::endl; |
36 | 40 | wasm_runtime_unload(module); |
| 41 | + wasm_runtime_destroy(); |
| 42 | + /* return SUCCESS because the failure has been handled */ |
| 43 | + return 0; |
37 | 44 | } |
38 | | - /* destroy runtime environment */ |
39 | | - wasm_runtime_destroy(); |
40 | 45 |
|
| 46 | + std::cout << "PASS" << std::endl; |
| 47 | + |
| 48 | + wasm_runtime_deinstantiate(inst); |
| 49 | + wasm_runtime_unload(module); |
| 50 | + wasm_runtime_destroy(); |
41 | 51 | return 0; /* Values other than 0 and -1 are reserved for future use. */ |
42 | 52 | } |
43 | 53 |
|
|
0 commit comments