Coverage Report

Created: 2025-07-11 06:33

/src/testdir/tests/capi/luaL_addgsub_test.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright 2023, Sergey Bronnikov.
5
 */
6
7
#include <stdint.h>
8
#include <stddef.h>
9
#include <string.h>
10
#include <stdlib.h>
11
12
#include <fuzzer/FuzzedDataProvider.h>
13
14
#if defined(__cplusplus)
15
extern "C" {
16
#endif /* defined(__cplusplus) */
17
18
#include "lua.h"
19
#include "lualib.h"
20
#include "lauxlib.h"
21
22
#if defined(__cplusplus)
23
} /* extern "C" */
24
#endif /* defined(__cplusplus) */
25
26
extern "C" int
27
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
28
747
{
29
747
  FuzzedDataProvider fdp(data, size);
30
31
747
  lua_State *L = luaL_newstate();
32
747
  if (L == NULL)
33
0
    return 0;
34
35
747
  luaL_Buffer buf;
36
747
  auto str = fdp.ConsumeRandomLengthString(size);
37
747
  luaL_buffinit(L, &buf);
38
747
  luaL_addstring(&buf, str.c_str());
39
40
747
  auto str1 = fdp.ConsumeRandomLengthString(size);
41
747
  auto str2 = fdp.ConsumeRandomLengthString(size);
42
747
  auto str3 = fdp.ConsumeRandomLengthString(size);
43
747
  const char *c_str1 = str1.c_str();
44
747
  const char *c_str2 = str2.c_str();
45
747
  const char *c_str3 = str3.c_str();
46
747
  if (strlen(c_str1) == 0 ||
47
747
      strlen(c_str2) == 0 ||
48
747
      strlen(c_str3) == 0) {
49
192
    luaL_pushresult(&buf);
50
192
    lua_settop(L, 0);
51
192
    lua_close(L);
52
192
    return -1;
53
192
  }
54
555
  luaL_addgsub(&buf, c_str1, c_str2, c_str3);
55
555
  luaL_pushresult(&buf);
56
57
555
  lua_settop(L, 0);
58
555
  lua_close(L);
59
60
555
  return 0;
61
747
}