[exprtk] Initial Integration (#4543)

This commit is contained in:
Arash Partow 2020-10-29 06:55:56 +11:00 committed by GitHub
parent 250926a9a4
commit 0c8e9162eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7355 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# Copyright 2020 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/ArashPartow/exprtk.git exprtk
WORKDIR exprtk
COPY build.sh exprtk_fuzzer.cpp exprtk_test_expressions.dict $SRC/

24
projects/exprtk/build.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash -eu
# Copyright 2020 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.
#
################################################################################
cp $SRC/*.dict $OUT/
CXXFLAGS="${CXXFLAGS} -O2 -fno-sanitize=integer-divide-by-zero,float-divide-by-zero"
$CXX -std=c++11 $CXXFLAGS -I. -I$SRC/exprtk \
$SRC/exprtk_fuzzer.cpp -o $OUT/exprtk_fuzzer \
$LIB_FUZZING_ENGINE

View File

@ -0,0 +1,58 @@
// Copyright 2020 Google LLC
//
// 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.
#include <cstdint>
#include <string>
#include "exprtk.hpp"
template <typename T>
void run(const std::string& expression_string)
{
typedef exprtk::symbol_table<T> symbol_table_t;
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
T x = T(1.2345);
T y = T(2.2345);
T z = T(3.2345);
T w = T(4.2345);
symbol_table_t symbol_table;
symbol_table.add_variable("x",x);
symbol_table.add_variable("y",y);
symbol_table.add_variable("z",z);
symbol_table.add_variable("w",w);
symbol_table.add_constants();
expression_t expression;
expression.register_symbol_table(symbol_table);
parser_t parser;
if (parser.compile(expression_string, expression))
{
expression.value();
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
const std::string expression(reinterpret_cast<const char*>(data), size);
run<double>(expression);
run<float> (expression);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
homepage: "https://www.partow.net/programming/exprtk/index.html"
language: c++
primary_contact: "exprtk.dev@gmail.com"
auto_ccs:
- "exprtk.dev@gmail.com"
fuzzing_engines:
- libfuzzer
- afl
- honggfuzz
sanitizers:
- address
- undefined
- memory