mirror of https://github.com/google/oss-fuzz.git
[libchewing] first fuzzer
libchewing is a library for Chinese character input.
This commit is contained in:
parent
e4c18c4797
commit
4dc6a2b23f
|
@ -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
|
|
@ -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"
|
||||||
|
}
|
|
@ -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
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue