Commit Briefs

Sergey Bronnikov

tests/capi: enable tests (ligurio/enable-lj-tests)

The commit 15388716f29d ("tests: disable lua_dump_test"). 1. https://github.com/ligurio/lua-c-api-tests/issues/19


Sergey Bronnikov

cfl: add a compiler flag used by Centipede


Sergey Bronnikov

docs: add citation information for the project

CITATION.cff files are plain text files with human- and machine-readable citation information for software (and datasets). Code developers can include them in their repositories to let others know how to correctly cite their software, see [1] and [2]. The patch adds a citation information for the project. 1. https://citation-file-format.github.io/ 2. https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-citation-files


Sergey Bronnikov

libluamut: initial version

The patch adds a shared library that implements a custom mutation and crossover functions for LibFuzzer. These functions allows to implement mutation and crossover logic with Lua programming language and thus replace the default mutation and crossover functions: `LLVMFuzzerCustomMutator` and `LLVMFuzzerCustomCrossover`. For implementing custom mutation function in Lua one need to create a Lua script with function `LLVMFuzzerCustomMutator` and set a path to the script in environment variable with name `LIBFUZZER_LUA_SCRIPT`. When this environment variable is not set default script name `libfuzzer_lua_script.lua` will be used. The same with custom crossover function - one need create a Lua script with defined Lua function `LLVMFuzzerCustomCrossover` and set a path to the script in environment variable `LIBFUZZER_LUA_SCRIPT`. Pay attention that both functions uses its own Lua state internally. Note, `libluamut` is unused now and building is disabled by default. Follows up #19


Sergey Bronnikov

tests: fix compiler warning

``` [60/62] Building CXX object tests/capi/luaL_loadbuffer_proto/CMakeFiles/luaL_loadbuffer_proto_test.dir/luaL_loadbuffer_proto_test.cc.o /home/runner/work/lua-c-api-tests/lua-c-api-tests/tests/capi/luaL_loadbuffer_proto/luaL_loadbuffer_proto_test.cc:308:30: warning: missing field 'B' initializer [-Wmissing-field-initializers] struct str_Writer state = {0}; ^ 1 warning generated. ```


Sergey Bronnikov

patches: fix PUC Rio Lua build

The commit 366c85564874 ("lua.c loads 'readline' dynamically") [1] breaks a build. The proposed patches fixes that. 1. https://github.com/lua/lua/commit/366c85564874d560b3608349f752e9e490f9002d


Sergey Bronnikov

cmake: update UBSan integration in LuaJIT

The patch updates integration of Undefined Behaviour Sanitizer with LuaJIT: some suppressions removed, some suppressions added per file, not project-wide. The patch is based on the patch made by Sergey Kaplun [1]. 1. https://github.com/tarantool/luajit/commit/b9ff5ae8ea60516f630a380948bfd140c237385a



Sergey Bronnikov

cfl: set fuzz-time to 2h


Sergey Bronnikov

tests/capi: speedup protobuf serialization

- clamp before cleaning string because cleaning is not cheap (O(n), where max n is equal to kMaxStrLength) - call cleaning for identifiers only, there is no sense to cleaning string literals - replace symbols disallowed by Lua grammar in indentifier's names with '_' The patch saves 16 sec on 145k samples (401 sec before the patch and 385 sec after the patch). It is actually not so much, but it is about 2.5 min per hour.


Branches





Tags

This repository contains no tags

Tree

.clusterfuzzlite/
.github/
.gitignorecommits | blame
.gitmodulescommits | blame
.luacheckrccommits | blame
CITATION.cffcommits | blame
CMakeLists.txtcommits | blame
CMakePresets.jsoncommits | blame
LICENSEcommits | blame
README.mdcommits | blame
TROPHIES.mdcommits | blame
cmake/
corpus$commits | blame
extra/
libluamut/
patches/
tests/

README.md

<table>
  <tr>
    <th>PUC Rio Lua</th>
    <td><a href="https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:lua"><img src="https://oss-fuzz-build-logs.storage.googleapis.com/badges/lua.svg"></a></td>
    <td><a href="https://github.com/ispras/oss-sydr-fuzz/tree/master/projects/lua"><img src="https://img.shields.io/static/v1?label=oss-sydr-fuzz&message=fuzzing&color=brightgreen"></a></td>
  </tr>
  <tr>
    <th>LuaJIT</th>
    <td></td>
    <td><a href="https://github.com/ispras/oss-sydr-fuzz/tree/master/projects/luajit"><img src="https://img.shields.io/static/v1?label=oss-sydr-fuzz&message=fuzzing&color=brightgreen"></a></td>
  </tr>
</table>

# Lua C API tests

is a set of fuzzing tests for C implementations of Lua runtime (PUC Rio Lua and
LuaJIT).

### Building

```sh
git clone --jobs $(nproc) --recursive https://github.com/ligurio/lua-c-api-tests
CC=clang CXX=clang++ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DUSE_LUA=ON [-DUSE_LUAJIT=ON]
cmake --build build --parallel
```

CMake options:

- `USE_LUA` enables building PUC Rio Lua.
- `USE_LUAJIT` enables building LuaJIT.
- `LUA_VERSION` could be a Git branch, tag or commit. By default `LUA_VERSION` is
`master` for PUC Rio Lua and `v2.1` for LuaJIT.
- `ENABLE_LUAJIT_RANDOM_RA` enables randomness in a register allocation. Option
is LuaJIT-specific.
- `ENABLE_ASAN` enables AddressSanitizer.
- `ENABLE_UBSAN` enables UndefinedBehaviorSanitizer.
- `ENABLE_COV` enables coverage instrumentation.
- `ENABLE_LUA_ASSERT` enables all assertions inside Lua source code.
- `ENABLE_LUA_APICHECK` enables consistency checks on the C API.
- `OSS_FUZZ` enables support of OSS Fuzz.
- `ENABLE_BUILD_PROTOBUF` enables building Protobuf library, otherwise system
  library is used.
- `ENABLE_INTERNAL_TESTS` enables internal tests.

### Running

```sh
cmake --build build --target test
cd build && RUNS=100000 ctest -R luaL_gsub_test --verbose
<snipped>
1: Done 100000 runs in 5 second(s)
```

### References

- [Lua 5.4 Reference Manual: 4 – The Application Program Interface](https://www.lua.org/manual/5.4/manual.html#4)
- [Lua 5.3 Reference Manual: 4 – The Application Program Interface](https://www.lua.org/manual/5.3/manual.html#4)
- [Lua 5.2 Reference Manual: 4 – The Application Program Interface](https://www.lua.org/manual/5.2/manual.html#4)
- [Lua 5.1 Reference Manual: 3 – The Application Program Interface](https://www.lua.org/manual/5.1/manual.html#3)

### License

Copyright (C) 2022-2024 [Sergey Bronnikov](https://bronevichok.ru/),
released under the ISC license. See a full Copyright Notice in the LICENSE file.