diff options
Diffstat (limited to 'projects/libchewing')
-rw-r--r-- | projects/libchewing/Dockerfile | 23 | ||||
-rwxr-xr-x | projects/libchewing/build.sh | 39 | ||||
-rw-r--r-- | projects/libchewing/chewing_default_fuzzer.c | 15 | ||||
-rw-r--r-- | projects/libchewing/chewing_dynamic_config_fuzzer.c | 15 | ||||
-rw-r--r-- | projects/libchewing/chewing_fuzzer_common.c | 26 | ||||
-rw-r--r-- | projects/libchewing/chewing_fuzzer_common.h | 13 | ||||
-rw-r--r-- | projects/libchewing/chewing_random_init_fuzzer.c | 15 | ||||
-rw-r--r-- | projects/libchewing/target.yaml | 1 |
8 files changed, 147 insertions, 0 deletions
diff --git a/projects/libchewing/Dockerfile b/projects/libchewing/Dockerfile new file mode 100644 index 00000000..50fb6939 --- /dev/null +++ b/projects/libchewing/Dockerfile @@ -0,0 +1,23 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +FROM ossfuzz/base-libfuzzer +MAINTAINER kcwu@csie.org +RUN apt-get install -y make autoconf automake libtool texinfo + +RUN git clone https://github.com/chewing/libchewing.git +WORKDIR libchewing +COPY build.sh chewing_fuzzer_common.[ch] chewing_*_fuzzer.c $SRC/ diff --git a/projects/libchewing/build.sh b/projects/libchewing/build.sh new file mode 100755 index 00000000..96f295ff --- /dev/null +++ b/projects/libchewing/build.sh @@ -0,0 +1,39 @@ +#!/bin/bash -eu +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# build the library. +./autogen.sh +./configure --disable-shared --enable-static --without-sqlite3 +make clean +make -j$(nproc) all + +# build your fuzzer(s) +make -C test CFLAGS="$CFLAGS -Dmain=stress_main -Drand=get_fuzz_input" stress.o + +$CC $CFLAGS -c $SRC/chewing_fuzzer_common.c -o $WORK/chewing_fuzzer_common.o + +for variant in default random_init dynamic_config; do + $CC $CFLAGS -c $SRC/chewing_${variant}_fuzzer.c -o $WORK/chewing_${variant}_fuzzer.o + $CXX $CXXFLAGS \ + -o $OUT/chewing_${variant}_fuzzer \ + $WORK/chewing_${variant}_fuzzer.o $WORK/chewing_fuzzer_common.o \ + test/stress.o test/.libs/libtesthelper.a src/.libs/libchewing.a \ + -lfuzzer +done + +# install data files +make -j$(nproc) -C data pkgdatadir=$OUT install diff --git a/projects/libchewing/chewing_default_fuzzer.c b/projects/libchewing/chewing_default_fuzzer.c new file mode 100644 index 00000000..dd6fc7a8 --- /dev/null +++ b/projects/libchewing/chewing_default_fuzzer.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "chewing_fuzzer_common.h" + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + fuzz_input = fuzz_ptr = data; + fuzz_size = size; + + const char* stress_argv[] = { + "./chewing_fuzzer", "-loop", "1", NULL, + }; + stress_main(sizeof(stress_argv) / sizeof(stress_argv[0]) - 1, + (char**)stress_argv); + return 0; +} diff --git a/projects/libchewing/chewing_dynamic_config_fuzzer.c b/projects/libchewing/chewing_dynamic_config_fuzzer.c new file mode 100644 index 00000000..5479c1ee --- /dev/null +++ b/projects/libchewing/chewing_dynamic_config_fuzzer.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "chewing_fuzzer_common.h" + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + fuzz_input = fuzz_ptr = data; + fuzz_size = size; + + const char* stress_argv[] = { + "./chewing_fuzzer", "-loop", "1", "-extra", NULL, + }; + stress_main(sizeof(stress_argv) / sizeof(stress_argv[0]) - 1, + (char**)stress_argv); + return 0; +} diff --git a/projects/libchewing/chewing_fuzzer_common.c b/projects/libchewing/chewing_fuzzer_common.c new file mode 100644 index 00000000..de249df6 --- /dev/null +++ b/projects/libchewing/chewing_fuzzer_common.c @@ -0,0 +1,26 @@ +#include "chewing_fuzzer_common.h" + +#include <libgen.h> +#include <stdio.h> +#include <stdlib.h> + +static char userphrase_path[] = "/tmp/chewing_userphrase.db.XXXXXX"; + +int LLVMFuzzerInitialize(int* argc, char*** argv) { + char* exe_path = (*argv)[0]; + char* dir = dirname(exe_path); + // Assume data files are at the same location as executable. + setenv("CHEWING_PATH", dir, 0); + + // Specify user db of this process. So we can run multiple fuzzers at the + // same time. + mktemp(userphrase_path); + setenv("TEST_USERPHRASE_PATH", userphrase_path, 0); + return 0; +} + +int get_fuzz_input() { + if (fuzz_ptr - fuzz_input >= fuzz_size) + return EOF; + return *fuzz_ptr++; +} diff --git a/projects/libchewing/chewing_fuzzer_common.h b/projects/libchewing/chewing_fuzzer_common.h new file mode 100644 index 00000000..5032d655 --- /dev/null +++ b/projects/libchewing/chewing_fuzzer_common.h @@ -0,0 +1,13 @@ +#ifndef CHEWING_FUZZER_COMMON_H +#define CHEWING_FUZZER_COMMON_H + +#include <stddef.h> +#include <stdint.h> + +const uint8_t* fuzz_ptr; +const uint8_t* fuzz_input; +size_t fuzz_size; + +int stress_main(int argc, char** argv); + +#endif diff --git a/projects/libchewing/chewing_random_init_fuzzer.c b/projects/libchewing/chewing_random_init_fuzzer.c new file mode 100644 index 00000000..e0d755f7 --- /dev/null +++ b/projects/libchewing/chewing_random_init_fuzzer.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +#include "chewing_fuzzer_common.h" + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + fuzz_input = fuzz_ptr = data; + fuzz_size = size; + + const char* stress_argv[] = { + "./chewing_fuzzer", "-loop", "1", "-init", NULL, + }; + stress_main(sizeof(stress_argv) / sizeof(stress_argv[0]) - 1, + (char**)stress_argv); + return 0; +} diff --git a/projects/libchewing/target.yaml b/projects/libchewing/target.yaml new file mode 100644 index 00000000..ef62bfe3 --- /dev/null +++ b/projects/libchewing/target.yaml @@ -0,0 +1 @@ +homepage: "http://chewing.im/" |