From 2915f19758be4cc891cfbd719c716db5f0c5a7a8 Mon Sep 17 00:00:00 2001 From: Kuang-che Wu Date: Thu, 20 Oct 2016 16:35:12 +0900 Subject: [PATCH] add fuzzer for libteken (#47) --- libteken/Dockerfile | 21 +++++++++++++++++++++ libteken/Jenkinsfile | 22 ++++++++++++++++++++++ libteken/build.sh | 28 ++++++++++++++++++++++++++++ libteken/libteken_fuzzer.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 libteken/Dockerfile create mode 100644 libteken/Jenkinsfile create mode 100755 libteken/build.sh create mode 100644 libteken/libteken_fuzzer.c diff --git a/libteken/Dockerfile b/libteken/Dockerfile new file mode 100644 index 000000000..2553441b2 --- /dev/null +++ b/libteken/Dockerfile @@ -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 pmake +RUN svn co https://svn.freebsd.org/base/head/sys/teken +COPY build.sh libteken_fuzzer.c /src/ diff --git a/libteken/Jenkinsfile b/libteken/Jenkinsfile new file mode 100644 index 000000000..7134a3dcf --- /dev/null +++ b/libteken/Jenkinsfile @@ -0,0 +1,22 @@ +// 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') + +libfuzzerBuild { + svn = "https://svn.freebsd.org/base/head/sys/teken" +} diff --git a/libteken/build.sh b/libteken/build.sh new file mode 100755 index 000000000..00e22cb1d --- /dev/null +++ b/libteken/build.sh @@ -0,0 +1,28 @@ +#!/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 + +# build the library. +pmake -C teken/libteken teken_state.h +CFLAGS="$CFLAGS -D__unused=" pmake -C teken/libteken libteken.a + +# build your fuzzer(s) +$CC $CFLAGS -Iteken \ + -o /out/libteken_fuzzer \ + libteken_fuzzer.c \ + -lfuzzer teken/libteken/libteken.a $FUZZER_LDFLAGS diff --git a/libteken/libteken_fuzzer.c b/libteken/libteken_fuzzer.c new file mode 100644 index 000000000..9335003b7 --- /dev/null +++ b/libteken/libteken_fuzzer.c @@ -0,0 +1,31 @@ +#include +#include + +#include + +static void dummy_bell(void *s) {} +static void dummy_cursor(void *s, const teken_pos_t *p) {} +static void dummy_putchar(void *s, const teken_pos_t *p, teken_char_t c, + const teken_attr_t *a) {} +static void dummy_fill(void *s, const teken_rect_t *r, teken_char_t c, + const teken_attr_t *a) {} +static void dummy_copy(void *s, const teken_rect_t *r, const teken_pos_t *p) {} +static void dummy_param(void *s, int cmd, unsigned int value) {} +static void dummy_respond(void *s, const void *buf, size_t len) {} + +static teken_funcs_t tf = { + .tf_bell = dummy_bell, + .tf_cursor = dummy_cursor, + .tf_putchar = dummy_putchar, + .tf_fill = dummy_fill, + .tf_copy = dummy_copy, + .tf_param = dummy_param, + .tf_respond = dummy_respond, +}; + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + teken_t t; + teken_init(&t, &tf, NULL); + teken_input(&t, data, size); + return 0; +}