Coverage Report

Created: 2023-08-27 06:20

/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
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
  luaL_Buffer buf;
30
829
  auto str = fdp.ConsumeRandomLengthString(size);
31
829
  luaL_buffinit(L, &buf);
32
829
  luaL_addstring(&buf, str.c_str());
33
34
829
  auto str1 = fdp.ConsumeRandomLengthString(size);
35
829
  auto str2 = fdp.ConsumeRandomLengthString(size);
36
829
  auto str3 = fdp.ConsumeRandomLengthString(size);
37
829
  const char *c_str1 = str1.c_str();
38
829
  const char *c_str2 = str2.c_str();
39
829
  const char *c_str3 = str3.c_str();
40
829
  if (strlen(c_str1) == 0 ||
41
829
      strlen(c_str2) == 0 ||
42
829
      strlen(c_str3) == 0) {
43
182
    luaL_pushresult(&buf);
44
182
    lua_settop(L, 0);
45
182
    lua_close(L);
46
182
    return -1;
47
182
  }
48
647
  luaL_addgsub(&buf, c_str1, c_str2, c_str3);
49
647
  luaL_pushresult(&buf);
50
51
647
  lua_settop(L, 0);
52
647
  lua_close(L);
53
54
647
  return 0;
55
829
}