/src/testdir/tests/capi/luaL_dostring_test.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright 2023, Sergey Bronnikov. |
5 | | */ |
6 | | |
7 | | #include <stdint.h> |
8 | | #include <stddef.h> |
9 | | #include <string.h> |
10 | | #include <stdlib.h> |
11 | | |
12 | | #include "lua.h" |
13 | | #include "lualib.h" |
14 | | #include "lauxlib.h" |
15 | | |
16 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
17 | 7.08k | { |
18 | 7.08k | lua_State *L = luaL_newstate(); |
19 | 7.08k | if (L == NULL) |
20 | 0 | return 0; |
21 | | |
22 | 7.08k | luaL_openlibs(L); |
23 | | |
24 | 7.08k | char *str = malloc(size + 1); |
25 | 7.08k | if (str == NULL) |
26 | 0 | return 0; |
27 | 7.08k | memcpy(str, data, size); |
28 | 7.08k | str[size] = '\0'; |
29 | | |
30 | | #ifdef LUAJIT |
31 | | /* See https://luajit.org/running.html. */ |
32 | | luaL_dostring(L, "jit.opt.start('hotloop=1')"); |
33 | | luaL_dostring(L, "jit.opt.start('hotexit=1')"); |
34 | | luaL_dostring(L, "jit.opt.start('recunroll=1')"); |
35 | | luaL_dostring(L, "jit.opt.start('callunroll=1')"); |
36 | | #endif /* LUAJIT */ |
37 | 7.08k | luaL_dostring(L, str); |
38 | | |
39 | 7.08k | free(str); |
40 | 7.08k | lua_settop(L, 0); |
41 | 7.08k | lua_close(L); |
42 | | |
43 | 7.08k | return 0; |
44 | 7.08k | } |