Coverage Report

Created: 2023-09-30 06:14

/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
778
{
24
778
  FuzzedDataProvider fdp(data, size);
25
26
778
  lua_State *L = luaL_newstate();
27
778
  if (L == NULL)
28
0
    return 0;
29
30
778
  auto str1 = fdp.ConsumeRandomLengthString(size);
31
778
  auto str2 = fdp.ConsumeRandomLengthString(size);
32
778
  auto str3 = fdp.ConsumeRandomLengthString(size);
33
778
  const char *c_str1 = str1.c_str();
34
778
  const char *c_str2 = str2.c_str();
35
778
  const char *c_str3 = str3.c_str();
36
778
  if (strlen(c_str1) == 0 ||
37
778
      strlen(c_str2) == 0 ||
38
778
      strlen(c_str3) == 0) {
39
151
    lua_settop(L, 0);
40
151
    lua_close(L);
41
151
    return -1;
42
151
  }
43
627
  int top = lua_gettop(L);
44
627
  luaL_gsub(L, c_str1, c_str2, c_str3);
45
  /* [-0, +1, m] */
46
627
  assert(lua_gettop(L) == top + 1);
47
48
0
  lua_settop(L, 0);
49
627
  lua_close(L);
50
51
627
  return 0;
52
778
}