Coverage Report

Created: 2023-09-15 06:13

/src/testdir/tests/luaL_addgsub_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
64
{
23
64
  FuzzedDataProvider fdp(data, size);
24
25
64
  lua_State *L = luaL_newstate();
26
64
  if (L == NULL)
27
0
    return 0;
28
29
64
  luaL_Buffer buf;
30
64
  auto str = fdp.ConsumeRandomLengthString(size);
31
64
  luaL_buffinit(L, &buf);
32
64
  luaL_addstring(&buf, str.c_str());
33
34
64
  auto str1 = fdp.ConsumeRandomLengthString(size);
35
64
  auto str2 = fdp.ConsumeRandomLengthString(size);
36
64
  auto str3 = fdp.ConsumeRandomLengthString(size);
37
64
  const char *c_str1 = str1.c_str();
38
64
  const char *c_str2 = str2.c_str();
39
64
  const char *c_str3 = str3.c_str();
40
64
  if (strlen(c_str1) == 0 ||
41
64
      strlen(c_str2) == 0 ||
42
64
      strlen(c_str3) == 0) {
43
25
    luaL_pushresult(&buf);
44
25
    lua_settop(L, 0);
45
25
    lua_close(L);
46
25
    return -1;
47
25
  }
48
39
  luaL_addgsub(&buf, c_str1, c_str2, c_str3);
49
39
  luaL_pushresult(&buf);
50
51
39
  lua_settop(L, 0);
52
39
  lua_close(L);
53
54
39
  return 0;
55
64
}