/src/testdir/tests/luaL_gsub_test.cc
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 <fuzzer/FuzzedDataProvider.h> |
7 | | |
8 | | #if defined(__cplusplus) |
9 | | extern "C" { |
10 | | #endif /* defined(__cplusplus) */ |
11 | | |
12 | | #include <lua.h> |
13 | | #include <lualib.h> |
14 | | #include <lauxlib.h> |
15 | | |
16 | | #if defined(__cplusplus) |
17 | | } /* extern "C" */ |
18 | | #endif /* defined(__cplusplus) */ |
19 | | |
20 | | extern "C" int |
21 | | LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
22 | 829 | { |
23 | 829 | FuzzedDataProvider fdp(data, size); |
24 | | |
25 | 829 | lua_State *L = luaL_newstate(); |
26 | 829 | if (L == NULL) |
27 | 0 | return 0; |
28 | | |
29 | 829 | auto str1 = fdp.ConsumeRandomLengthString(size); |
30 | 829 | auto str2 = fdp.ConsumeRandomLengthString(size); |
31 | 829 | auto str3 = fdp.ConsumeRandomLengthString(size); |
32 | 829 | const char *c_str1 = str1.c_str(); |
33 | 829 | const char *c_str2 = str2.c_str(); |
34 | 829 | const char *c_str3 = str3.c_str(); |
35 | 829 | if (strlen(c_str1) == 0 || |
36 | 829 | strlen(c_str2) == 0 || |
37 | 829 | strlen(c_str3) == 0) { |
38 | 182 | lua_settop(L, 0); |
39 | 182 | lua_close(L); |
40 | 182 | return -1; |
41 | 182 | } |
42 | 647 | luaL_gsub(L, c_str1, c_str2, c_str3); |
43 | | |
44 | 647 | lua_settop(L, 0); |
45 | 647 | lua_close(L); |
46 | | |
47 | 647 | return 0; |
48 | 829 | } |