From 3c3648fd1db45d795de23a5eabb46b8daa4dab2e Mon Sep 17 00:00:00 2001 From: Markus Kusano Date: Wed, 19 Dec 2018 23:20:49 -0500 Subject: [PATCH] Integrate libsass and add a fuzz target. (#2039) --- projects/libsass/Dockerfile | 22 +++++++++++++++++ projects/libsass/build.sh | 26 ++++++++++++++++++++ projects/libsass/data_context_fuzzer.cc | 32 +++++++++++++++++++++++++ projects/libsass/project.yaml | 13 ++++++++++ 4 files changed, 93 insertions(+) create mode 100644 projects/libsass/Dockerfile create mode 100755 projects/libsass/build.sh create mode 100644 projects/libsass/data_context_fuzzer.cc create mode 100644 projects/libsass/project.yaml diff --git a/projects/libsass/Dockerfile b/projects/libsass/Dockerfile new file mode 100644 index 000000000..93ad9874c --- /dev/null +++ b/projects/libsass/Dockerfile @@ -0,0 +1,22 @@ +# Copyright 2018 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 gcr.io/oss-fuzz-base/base-builder +RUN apt-get update && apt-get install -y make autoconf automake libtool +RUN git clone --depth 1 https://github.com/sass/libsass.git libsass +WORKDIR $SRC +COPY build.sh $SRC/ +COPY data_context_fuzzer.cc $SRC/ diff --git a/projects/libsass/build.sh b/projects/libsass/build.sh new file mode 100755 index 000000000..ee8866c45 --- /dev/null +++ b/projects/libsass/build.sh @@ -0,0 +1,26 @@ +#!/bin/bash -eu +# Copyright 2018 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. +# +################################################################################ + +pushd libsass +export BUILD='static' +make -j$(nproc) +popd + +INSTALL_DIR="$SRC/libsass" + +$CXX $CXXFLAGS -I${INSTALL_DIR}/include -lFuzzingEngine data_context_fuzzer.cc \ + -o $OUT/data_context_fuzzer ${INSTALL_DIR}/lib/libsass.a diff --git a/projects/libsass/data_context_fuzzer.cc b/projects/libsass/data_context_fuzzer.cc new file mode 100644 index 000000000..310e43e7e --- /dev/null +++ b/projects/libsass/data_context_fuzzer.cc @@ -0,0 +1,32 @@ +#include "sass.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + char* sass_data = (char*) malloc(sizeof(char) * size + 1); + if (sass_data == NULL) return 0; + + memcpy(sass_data, data, size); + sass_data[size] = '\0'; + + struct Sass_Data_Context* ctx = sass_make_data_context(sass_data); + if (ctx == NULL) { + free(sass_data); + return 0; + } + + struct Sass_Options* options = sass_make_options(); + if (options == NULL) { + sass_delete_data_context(ctx); + return 0; + } + + sass_option_set_output_style(options, SASS_STYLE_NESTED); + sass_option_set_precision(options, 5); + + sass_data_context_set_options(ctx, options); + sass_compile_data_context(ctx); + + sass_delete_data_context(ctx); + sass_delete_options(options); + + return 0; +} diff --git a/projects/libsass/project.yaml b/projects/libsass/project.yaml new file mode 100644 index 000000000..f8794866c --- /dev/null +++ b/projects/libsass/project.yaml @@ -0,0 +1,13 @@ +homepage: "http://libsass.org/" +primary_contact: "kusano@google.com" + +experimental: true + +sanitizers: + - address + - memory + - undefined + +labels: + data_context_fuzze: + - sundew