Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClusterFuzzLite build integration #280

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gcr.io/oss-fuzz-base/base-builder:v1
RUN apt-get update && apt-get install -y make autoconf automake libtool meson bison libxml2-dev pkg-config valgrind
COPY . $SRC/libxkbcommon
WORKDIR $SRC/libxkbcommon
COPY .clusterfuzzlite/build.sh $SRC/
12 changes: 12 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -eu
# https://google.github.io/clusterfuzzlite/build-integration/

: ${LD:="${CXX}"}
: ${LDFLAGS:="${CXXFLAGS}"}

rm -rf build
meson setup build -Denable-x11=false -Denable-wayland=false -Denable-docs=false
ninja -C build

# "even if your project is written in pure C you must use $CXX to link your fuzz target binaries"
$CXX $CXXFLAGS -std=c++11 -Ibuild/ $SRC/fuzz/compose/target.c -o $OUT/compose_fuzzer $LIB_FUZZING_ENGINE build/libxkbcommon.so
1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: c
35 changes: 7 additions & 28 deletions fuzz/compose/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,16 @@
#include "xkbcommon/xkbcommon.h"
#include "xkbcommon/xkbcommon-compose.h"

int
main(int argc, char *argv[])
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
struct xkb_context *ctx;
FILE *file;
struct xkb_compose_table *table;

if (argc != 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]);
return 1;
}

ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES); // | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
assert(ctx);

#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();

while (__AFL_LOOP(1000))
#endif
{
file = fopen(argv[1], "rb");
assert(file);
table = xkb_compose_table_new_from_file(ctx, file,
"en_US.UTF-8",
XKB_COMPOSE_FORMAT_TEXT_V1,
XKB_COMPOSE_COMPILE_NO_FLAGS);
xkb_compose_table_unref(table);
fclose(file);
}

puts(table ? "OK" : "FAIL");
table = xkb_compose_table_new_from_buffer(ctx, (const char*) data, size, "en_US.UTF-8",
XKB_COMPOSE_FORMAT_TEXT_V1,
XKB_COMPOSE_COMPILE_NO_FLAGS);
xkb_compose_table_unref(table);
xkb_context_unref(ctx);
return 0;
}
33 changes: 7 additions & 26 deletions fuzz/keymap/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,17 @@

#include "xkbcommon/xkbcommon.h"

int
main(int argc, char *argv[])
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
struct xkb_context *ctx;
FILE *file;
struct xkb_keymap *keymap;

if (argc != 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]);
return 1;
}

ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
assert(ctx);

#ifdef __AFL_HAVE_MANUAL_CONTROL
__AFL_INIT();

while (__AFL_LOOP(1000))
#endif
{
file = fopen(argv[1], "rb");
assert(file);
keymap = xkb_keymap_new_from_file(ctx, file,
XKB_KEYMAP_FORMAT_TEXT_V1,
XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_keymap_unref(keymap);
fclose(file);
}

puts(keymap ? "OK" : "FAIL");
keymap = xkb_keymap_new_from_buffer(ctx, data, size,
XKB_KEYMAP_FORMAT_TEXT_V1,
XKB_KEYMAP_COMPILE_NO_FLAGS);
xkb_keymap_unref(keymap);
xkb_context_unref(ctx);
return 0;
}

7 changes: 2 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cflags = [
'-fno-strict-aliasing',
'-fsanitize-undefined-trap-on-error',
'-Wno-unused-parameter',
'-Wno-unused-function',
'-Wno-missing-field-initializers',
'-Wpointer-arith',
'-Wmissing-declarations',
Expand All @@ -32,6 +33,7 @@ cflags = [
'-Wdate-time',
'-Wwrite-strings',
'-Wno-documentation-deprecated-sync',
'-Werror=unused-command-line-argument',
]
add_project_arguments(cc.get_supported_arguments(cflags), language: 'c')

Expand Down Expand Up @@ -726,11 +728,6 @@ else
endif


# Fuzzing target programs.
executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)


# Benchmarks.
bench_env = environment()
bench_env.set('top_srcdir', meson.source_root())
Expand Down