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

Add fuzzer for libchewing #5

Merged
merged 1 commit into from
Oct 6, 2016
Merged
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
21 changes: 21 additions & 0 deletions libchewing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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

CMD /src/oss-fuzz/libchewing/build.sh
23 changes: 23 additions & 0 deletions libchewing/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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.
//
////////////////////////////////////////////////////////////////////////////////

def libfuzzerBuild = fileLoader.fromGit('infra/libfuzzer-pipeline.groovy',
'https://github.com/google/oss-fuzz.git',
'master', null, '')

libfuzzerBuild {
git = "https://github.com/chewing/libchewing.git"
}
35 changes: 35 additions & 0 deletions libchewing/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.
#
################################################################################

cd /src/libchewing

# build the library.
./autogen.sh
./configure --disable-shared --enable-static --without-sqlite3
make clean all

# build your fuzzer(s)
make -C test CFLAGS="$CFLAGS -Dmain=stress_main -Drand=get_fuzz_input" stress.o

./libtool --mode=link \
$CC $CFLAGS \
-o /out/chewing_fuzzer \
/src/oss-fuzz/libchewing/chewing_fuzzer.c \
test/stress.o test/libtesthelper.la src/libchewing.la $LDFLAGS /work/libfuzzer/*.o

# install data files
make -C data pkgdatadir=/out install
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also creates /out/.libs file
Can these be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it tomorrow

40 changes: 40 additions & 0 deletions libchewing/chewing_fuzzer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>

static const uint8_t* fuzz_ptr;
static const uint8_t* fuzz_input;
static size_t fuzz_size;

int stress_main(int argc, char** argv);

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);
setenv("CHEWING_USER_PATH", dir, 0);
return 0;
}

int get_fuzz_input() {
if (fuzz_ptr - fuzz_input >= fuzz_size)
return EOF;
return *fuzz_ptr++;
}

int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
fuzz_input = fuzz_ptr = data;
fuzz_size = size;

const char *stress_argv[] = {
"./chewing_fuzzer",
"-extra",
"-loop", "1",
NULL,
};
stress_main(4, (char**)stress_argv);
return 0;
}