Skip to content

Commit 5a063ce

Browse files
committed
~/oss-fuzz/infra/helper.py build_fuzzers --external ~/libxkbcommon Not yet working
1 parent 3d56569 commit 5a063ce

6 files changed

Lines changed: 34 additions & 59 deletions

File tree

.clusterfuzzlite/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM gcr.io/oss-fuzz-base/base-builder:v1
2+
RUN apt-get update && apt-get install -y make autoconf automake libtool meson bison libxml2-dev pkg-config valgrind
3+
COPY . $SRC/libxkbcommon
4+
WORKDIR $SRC/libxkbcommon
5+
COPY .clusterfuzzlite/build.sh $SRC/

.clusterfuzzlite/build.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash -eu
2+
# https://google.github.io/clusterfuzzlite/build-integration/
3+
4+
: ${LD:="${CXX}"}
5+
: ${LDFLAGS:="${CXXFLAGS}"}
6+
7+
rm -rf build
8+
meson setup build -Denable-x11=false -Denable-wayland=false -Denable-docs=false
9+
ninja -C build
10+
11+
# "even if your project is written in pure C you must use $CXX to link your fuzz target binaries"
12+
$CXX $CXXFLAGS -std=c++11 -Ibuild/ $SRC/fuzz/compose/target.c -o $OUT/compose_fuzzer $LIB_FUZZING_ENGINE build/libxkbcommon.so

.clusterfuzzlite/project.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: c

fuzz/compose/target.c

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,16 @@
1010
#include "xkbcommon/xkbcommon.h"
1111
#include "xkbcommon/xkbcommon-compose.h"
1212

13-
int
14-
main(int argc, char *argv[])
13+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
1514
{
1615
struct xkb_context *ctx;
17-
FILE *file;
1816
struct xkb_compose_table *table;
19-
20-
if (argc != 2) {
21-
fprintf(stderr, "usage: %s <file>\n", argv[0]);
22-
return 1;
23-
}
24-
25-
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
17+
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES); // | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
2618
assert(ctx);
27-
28-
#ifdef __AFL_HAVE_MANUAL_CONTROL
29-
__AFL_INIT();
30-
31-
while (__AFL_LOOP(1000))
32-
#endif
33-
{
34-
file = fopen(argv[1], "rb");
35-
assert(file);
36-
table = xkb_compose_table_new_from_file(ctx, file,
37-
"en_US.UTF-8",
38-
XKB_COMPOSE_FORMAT_TEXT_V1,
39-
XKB_COMPOSE_COMPILE_NO_FLAGS);
40-
xkb_compose_table_unref(table);
41-
fclose(file);
42-
}
43-
44-
puts(table ? "OK" : "FAIL");
19+
table = xkb_compose_table_new_from_buffer(ctx, (const char*) data, size, "en_US.UTF-8",
20+
XKB_COMPOSE_FORMAT_TEXT_V1,
21+
XKB_COMPOSE_COMPILE_NO_FLAGS);
22+
xkb_compose_table_unref(table);
4523
xkb_context_unref(ctx);
24+
return 0;
4625
}

fuzz/keymap/target.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,17 @@
99

1010
#include "xkbcommon/xkbcommon.h"
1111

12-
int
13-
main(int argc, char *argv[])
12+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
1413
{
1514
struct xkb_context *ctx;
16-
FILE *file;
1715
struct xkb_keymap *keymap;
18-
19-
if (argc != 2) {
20-
fprintf(stderr, "usage: %s <file>\n", argv[0]);
21-
return 1;
22-
}
23-
2416
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);
2517
assert(ctx);
26-
27-
#ifdef __AFL_HAVE_MANUAL_CONTROL
28-
__AFL_INIT();
29-
30-
while (__AFL_LOOP(1000))
31-
#endif
32-
{
33-
file = fopen(argv[1], "rb");
34-
assert(file);
35-
keymap = xkb_keymap_new_from_file(ctx, file,
36-
XKB_KEYMAP_FORMAT_TEXT_V1,
37-
XKB_KEYMAP_COMPILE_NO_FLAGS);
38-
xkb_keymap_unref(keymap);
39-
fclose(file);
40-
}
41-
42-
puts(keymap ? "OK" : "FAIL");
18+
keymap = xkb_keymap_new_from_buffer(ctx, data, size,
19+
XKB_KEYMAP_FORMAT_TEXT_V1,
20+
XKB_KEYMAP_COMPILE_NO_FLAGS);
21+
xkb_keymap_unref(keymap);
4322
xkb_context_unref(ctx);
23+
return 0;
4424
}
25+

meson.build

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cflags = [
1919
'-fno-strict-aliasing',
2020
'-fsanitize-undefined-trap-on-error',
2121
'-Wno-unused-parameter',
22+
'-Wno-unused-function',
2223
'-Wno-missing-field-initializers',
2324
'-Wpointer-arith',
2425
'-Wmissing-declarations',
@@ -32,6 +33,7 @@ cflags = [
3233
'-Wdate-time',
3334
'-Wwrite-strings',
3435
'-Wno-documentation-deprecated-sync',
36+
'-Werror=unused-command-line-argument',
3537
]
3638
add_project_arguments(cc.get_supported_arguments(cflags), language: 'c')
3739

@@ -726,11 +728,6 @@ else
726728
endif
727729

728730

729-
# Fuzzing target programs.
730-
executable('fuzz-keymap', 'fuzz/keymap/target.c', dependencies: test_dep)
731-
executable('fuzz-compose', 'fuzz/compose/target.c', dependencies: test_dep)
732-
733-
734731
# Benchmarks.
735732
bench_env = environment()
736733
bench_env.set('top_srcdir', meson.source_root())

0 commit comments

Comments
 (0)