Skip to content

Commit e4f8214

Browse files
committed
tests: introduce ffi_cdef_proto_test
LuaJIT has a FFI library which allows calling external C functions and using C data structures from a pure Lua code, see [1]. According to a FFI API documentation [2] the Lua function `ffi.cdef(def)` adds multiple C declarations for types or external symbols (named variables or functions). `def` must be a Lua string. The contents of the string `def` must be a sequence of C declarations, separated by semicolons. The C parser complies to the C99 language standard plus the extensions described in [3]. Note, LuaJIT C parser is not a validating C parser. It expects and accepts correctly formed C declarations. Therefore without grammar-aware fuzzing we will face with a false-positive crashes. The patch adds a grammar-aware test, where C declarations generated automatically using Protobuf grammar and LibProtoBuf-mutator and then serialize Protobuf structure to a string. Note, an implementation is not finished yet. An example of bug in `src/lj_cparse.c` is LJ#1114. 1. https://luajit.org/ext_ffi.html 2. https://luajit.org/ext_ffi_api.html 3. https://luajit.org/ext_ffi_semantics.html#clang 4. https://luajit.org/ext_ffi_semantics.html#status
1 parent 0e60f36 commit e4f8214

File tree

6 files changed

+1747
-0
lines changed

6 files changed

+1747
-0
lines changed

tests/capi/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@ endforeach()
134134

135135
include(ProtobufMutator)
136136
add_subdirectory(luaL_loadbuffer_proto)
137+
if(USE_LUAJIT)
138+
add_subdirectory(ffi_cdef_proto)
139+
endif ()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(test_name ffi_cdef_proto_test)
2+
3+
add_library(cdef-proto)
4+
5+
foreach(lib ${LPM_LIBRARIES})
6+
find_library(${lib} REQUIRED_FILES)
7+
endforeach(lib)
8+
9+
protobuf_generate(LANGUAGE cpp
10+
TARGET cdef-proto
11+
PROTOS cdef.proto)
12+
13+
target_link_libraries(cdef-proto
14+
${PROTOBUF_LIBRARIES})
15+
16+
create_test(FILENAME ${test_name}
17+
SOURCES ffi_cdef_proto_test.cc cdef_print.cc
18+
LIBRARIES cdef-proto ${LPM_LIBRARIES})
19+
20+
target_include_directories(${test_name}
21+
PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${LUA_INCLUDE_DIR})
22+
add_dependencies(${test_name} ${LPM_LIBRARIES} cdef-proto)

0 commit comments

Comments
 (0)