Coverage Report

Created: 2025-07-11 06:33

/src/testdir/tests/capi/luaL_loadstring_test.c
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
#include <assert.h>
12
13
#include "lua.h"
14
#include "lualib.h"
15
#include "lauxlib.h"
16
17
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
18
2.42k
{
19
2.42k
  lua_State *L = luaL_newstate();
20
2.42k
  if (L == NULL)
21
0
    return 0;
22
23
2.42k
  luaL_openlibs(L);
24
25
2.42k
  char *str = malloc(size + 1);
26
2.42k
  if (str == NULL)
27
0
    return 0;
28
2.42k
  memcpy(str, data, size);
29
2.42k
  str[size] = '\0';
30
31
#ifdef LUAJIT
32
  /* See https://luajit.org/running.html. */
33
  luaL_dostring(L, "jit.opt.start('hotloop=1')");
34
  luaL_dostring(L, "jit.opt.start('hotexit=1')");
35
  luaL_dostring(L, "jit.opt.start('recunroll=1')");
36
  luaL_dostring(L, "jit.opt.start('callunroll=1')");
37
#endif /* LUAJIT */
38
39
2.42k
  if (luaL_loadstring(L, str) != LUA_OK) {
40
598
    goto end;
41
598
  }
42
43
1.82k
  lua_pcall(L, 0, 0, 0);
44
45
2.42k
end:
46
2.42k
  free(str);
47
2.42k
  lua_settop(L, 0);
48
2.42k
  lua_close(L);
49
50
2.42k
  return 0;
51
1.82k
}