Coverage Report

Created: 2023-08-27 06:20

/src/testdir/tests/luaL_buffsub_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
#include <assert.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
522
{
24
522
  FuzzedDataProvider fdp(data, size);
25
26
522
  lua_State *L = luaL_newstate();
27
522
  if (L == NULL)
28
0
    return 0;
29
30
522
  auto str = fdp.ConsumeRandomLengthString(size);
31
522
  size_t buf_size = str.length() + 1;
32
522
  uint8_t n = fdp.ConsumeIntegralInRange<uint8_t>(0, buf_size);
33
34
522
  luaL_Buffer buf;
35
522
  luaL_buffinit(L, &buf);
36
522
  luaL_addlstring(&buf, str.c_str(), buf_size);
37
522
  luaL_buffsub(&buf, n);
38
522
  luaL_pushresult(&buf);
39
40
522
  assert(luaL_bufflen(&buf) == buf_size - n);
41
0
  lua_settop(L, 0);
42
522
  lua_close(L);
43
44
522
  return 0;
45
522
}