Coverage Report

Created: 2025-08-29 06:37

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