Coverage Report

Created: 2023-09-15 06:20

/src/testdir/tests/luaL_gsub_test.cc
Line
Count
Source (jump to first uncovered line)
1
#include <assert.h>
2
#include <stdint.h>
3
#include <stddef.h>
4
#include <string.h>
5
#include <stdlib.h>
6
7
#include <fuzzer/FuzzedDataProvider.h>
8
9
#if defined(__cplusplus)
10
extern "C" {
11
#endif /* defined(__cplusplus) */
12
13
#include <lua.h>
14
#include <lualib.h>
15
#include <lauxlib.h>
16
17
#if defined(__cplusplus)
18
} /* extern "C" */
19
#endif /* defined(__cplusplus) */
20
21
extern "C" int
22
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
23
50
{
24
50
  FuzzedDataProvider fdp(data, size);
25
26
50
  lua_State *L = luaL_newstate();
27
50
  if (L == NULL)
28
0
    return 0;
29
30
50
  auto str1 = fdp.ConsumeRandomLengthString(size);
31
50
  auto str2 = fdp.ConsumeRandomLengthString(size);
32
50
  auto str3 = fdp.ConsumeRandomLengthString(size);
33
50
  const char *c_str1 = str1.c_str();
34
50
  const char *c_str2 = str2.c_str();
35
50
  const char *c_str3 = str3.c_str();
36
50
  if (strlen(c_str1) == 0 ||
37
50
      strlen(c_str2) == 0 ||
38
50
      strlen(c_str3) == 0) {
39
21
    lua_settop(L, 0);
40
21
    lua_close(L);
41
21
    return -1;
42
21
  }
43
29
  int top = lua_gettop(L);
44
29
  luaL_gsub(L, c_str1, c_str2, c_str3);
45
  /* [-0, +1, m] */
46
29
  assert(lua_gettop(L) == top + 1);
47
48
0
  lua_settop(L, 0);
49
29
  lua_close(L);
50
51
29
  return 0;
52
50
}