/src/testdir/tests/luaL_loadbufferx_test.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include <stdint.h> |
2 | | #include <stddef.h> |
3 | | #include <string.h> |
4 | | #include <stdlib.h> |
5 | | |
6 | | #include <lua.h> |
7 | | #include <lualib.h> |
8 | | #include <lauxlib.h> |
9 | | |
10 | | |
11 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
12 | 30 | { |
13 | 30 | lua_State *L = luaL_newstate(); |
14 | 30 | if (L == NULL) |
15 | 0 | return 0; |
16 | | |
17 | 30 | luaL_openlibs(L); |
18 | | |
19 | | #ifdef LUAJIT |
20 | | /* See https://luajit.org/running.html. */ |
21 | | luaL_dostring(L, "jit.opt.start('hotloop=1')"); |
22 | | luaL_dostring(L, "jit.opt.start('hotexit=1')"); |
23 | | luaL_dostring(L, "jit.opt.start('recunroll=1')"); |
24 | | luaL_dostring(L, "jit.opt.start('callunroll=1')"); |
25 | | #endif /* LUAJIT */ |
26 | | |
27 | 30 | const char *mode = "t"; |
28 | 30 | int res = luaL_loadbufferx(L, (const char *)data, size, "fuzz", mode); |
29 | 30 | if (res == LUA_OK) { |
30 | 17 | lua_pcall(L, 0, 0, 0); |
31 | 17 | } |
32 | | |
33 | 30 | lua_settop(L, 0); |
34 | 30 | lua_close(L); |
35 | | |
36 | 30 | return 0; |
37 | 30 | } |