Skip to content

Commit

Permalink
[libchewing] first fuzzer
Browse files Browse the repository at this point in the history
libchewing is a library for Chinese character input.
  • Loading branch information
kcwu authored and mikea committed Oct 6, 2016
1 parent e4c18c4 commit 4dc6a2b
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
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
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;
}

0 comments on commit 4dc6a2b

Please sign in to comment.