Integrate libsass and add a fuzz target. (#2039)

This commit is contained in:
Markus Kusano 2018-12-19 23:20:49 -05:00 committed by jonathanmetzman
parent b6aefa51cb
commit 3c3648fd1d
4 changed files with 93 additions and 0 deletions

View File

@ -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/

26
projects/libsass/build.sh Executable file
View File

@ -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

View File

@ -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;
}

View File

@ -0,0 +1,13 @@
homepage: "http://libsass.org/"
primary_contact: "kusano@google.com"
experimental: true
sanitizers:
- address
- memory
- undefined
labels:
data_context_fuzze:
- sundew