Skip to content

Commit

Permalink
fix #67, fix #64, fix #62, fix #63
Browse files Browse the repository at this point in the history
  • Loading branch information
thientc committed Apr 5, 2023
1 parent d07686c commit 69c2971
Show file tree
Hide file tree
Showing 25 changed files with 712 additions and 250 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Add Fuzzer extra params support

## 20230320
- Support for context generation
- Support for context generation

## 20230305
- Fix error python in Builder
- Fix error python in Generator for wchar_t string
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Additionally, Futag provides the ability to test compiled targets.
You can try to build Futag with pre-built [Docker files](https://github.com/ispras/Futag/tree/main/product-tests/build-test) for Ubuntu OS.

### 2.2. Using a prepackaged package
Download the latest [futag-llvm.2.0.0.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.0) and unzip
Download the latest [futag-llvm.2.0.1.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.0) and unzip

### 2.3. Building and installing from source

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ FUTAG использует, в качестве внешнего интерф
Вы можете попробовать собрать Futag с готовыми [Докер-файлами](https://github.com/ispras/Futag/tree/main/product-tests/build-test) для ОС Ubuntu.

## 2.2. Использование предварительно упакованного пакета
- Загрузите последнюю версию [futag-llvm.2.0.0.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.0) и разархивируйте.
- Загрузите последнюю версию [futag-llvm.2.0.1.tar.xz](https://github.com/ispras/Futag/releases/tag/2.0.0) и разархивируйте.

## 2.3. Сборка и установка из исходного кода

Expand Down Expand Up @@ -82,8 +82,9 @@ FUTAG использует, в качестве внешнего интерф
- Предварительно должен быть установлен пакет futag-<версия>.tar.gz по пути futag-llvm/python-package/:
```bash
~$ pip install -r futag-llvm/python-package/requirements.txt
~$ pip install futag-llvm/python-package/futag-2.0.0.tar.gz
~$ pip install futag-llvm/python-package/futag-2.0.1.tar.gz
```
- Для того, чтобы Futag генерировал фаззинг-обертки в формате AFLplusplus необходимо запустить скрипт futag-llvm/export.sh

### 3.1. Автоматическая генерация фаззинг-оберток в условии отсутствия контекстов использования
- Запуск сборки, проверки и анализа в условии отсутствия контекстов использования
Expand Down Expand Up @@ -184,6 +185,7 @@ context_generator.compile_targets( #компиляция сгенерирова
## 5. Статьи и материалы

- C. T. Tran and S. Kurmangaleev, ["Futag: Automated fuzz target generator for testing software libraries"](https://ieeexplore.ieee.org/document/9693749) 2021 Ivannikov Memorial Workshop (IVMEM), 2021, pp. 80-85, doi: 10.1109/IVMEM53963.2021.00021.
- C. T. Tran, D. Ponomarev and A. Kuznhesov, ["Research on automatic generation of fuzz-target for software library functions"](https://ieeexplore.ieee.org/document/10076871), 2022 Ivannikov Ispras Open Conference (ISPRAS), Moscow, Russian Federation, 2022, pp. 95-99, doi: 10.1109/ISPRAS57371.2022.10076871.

- Исследования по автоматической генерации фаззинг-оберток для функций библиотек, Открытая конференция ИСП РАН им. В.П. Иванникова 2022

Expand Down
2 changes: 1 addition & 1 deletion custom-llvm/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

#===-- build.bash -------*- bash script -*-===//
#===-- build.sh -------*- bash script -*-===//
#
# This file is distributed under the GPL v3 license (https://www.gnu.org/licenses/gpl-3.0.en.html).
#
Expand Down
7 changes: 4 additions & 3 deletions custom-llvm/buildwAFLplusplus.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

#===-- build.bash -------*- bash script -*-===//
#===-- build.sh -------*- bash script -*-===//
#
# This file is distributed under the GPL v3 license (https://www.gnu.org/licenses/gpl-3.0.en.html).
#
Expand Down Expand Up @@ -55,11 +55,11 @@ cp $futag_src/Checkers/lib/*.cpp $custom_llvm/clang/lib/StaticAnalyzer/Checkers/
cp -r $futag_src/Checkers/lib/$CheckerCMakeLists $custom_llvm/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt

if [ $llvmVersion == "LLVM=14.0.6" ]; then
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_RUNTIMES="compiler-rt;" $custom_llvm/llvm
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" -DLLVM_ENABLE_RUNTIMES="compiler-rt;" $custom_llvm/llvm

fi
if [ $llvmVersion == "LLVM=13.0.1" ]; then
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;compiler-rt;' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" $custom_llvm/llvm
cmake -G "Unix Makefiles" -DLLVM_BUILD_TESTS=OFF -DLLVM_ENABLE_ZLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_BINUTILS_INCDIR=/usr/include/ -DCMAKE_INSTALL_PREFIX=$futag_install_folder -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCLANG_INCLUDE_DOCS="OFF" -DLLVM_BUILD_LLVM_DYLIB="ON" -DLLVM_ENABLE_BINDINGS="OFF" -DLLVM_ENABLE_PROJECTS='clang;compiler-rt;' -DLLVM_ENABLE_WARNINGS="OFF" -DLLVM_INCLUDE_BENCHMARKS="OFF" -DLLVM_INCLUDE_DOCS="OFF" -DLLVM_INCLUDE_EXAMPLES="OFF" -DLLVM_INCLUDE_TESTS="OFF" -DLLVM_LINK_LLVM_DYLIB="ON" -DLLVM_TARGETS_TO_BUILD="host" $custom_llvm/llvm

fi
make -j$(($(nproc)/2)) && make -j$(($(nproc)/2)) install
Expand All @@ -86,6 +86,7 @@ cp -r $futag_src/svres-tmpl $futag_install_folder/
cp -r ../*.md $futag_install_folder/
cp -r ../LICENSE $futag_install_folder/
cp $custom_prepare/INFO $futag_install_folder/
cp $custom_prepare/export.sh $futag_install_folder/
git rev-parse HEAD >> $futag_install_folder/INFO

cd ../product-tests
Expand Down
27 changes: 27 additions & 0 deletions custom-llvm/export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

#===-- export.sh -------*- bash script -*-===//
#
# This file is distributed under the GPL v3 license (https://www.gnu.org/licenses/gpl-3.0.en.html).
#
# This script helps to build llvm with clang and compiler-rt

echo "************************************************"
echo "* ______ __ __ ______ ___ ______ *"
echo "* / ____/ / / / / /_ __/ / | / ____/ *"
echo "* / /_ / / / / / / / /| | / / __ *"
echo "* / __/ / /_/ / / / / ___ | / /_/ / *"
echo "* /_/ \____/ /_/ /_/ |_| \____/ *"
echo "* *"
echo "* Fuzzing target Automated Generator *"
echo "* a tool of ISP RAS *"
echo "************************************************"
echo ""

SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
echo "Exporting Futag path for AFLplusplus: "$SCRIPTPATH
echo ""
set -x
export PATH="$SCRIPTPATH/bin:$PATH"
export LLVM_CONFIG="$SCRIPTPATH/bin/llvm-config"
export LD_LIBRARY_PATH="$(llvm-config --libdir)${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN ./build.sh

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN ./build.sh

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz

USER futag
WORKDIR /home/futag/Futag/
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ WORKDIR /home/futag/Futag-tests
RUN ./get-Futag.sh

USER root
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN ./get-Futag.sh

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ADD futag-llvm.latest.tar.xz /home/futag/Futag/

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ADD futag-llvm.latest.tar.xz /home/futag/Futag

USER root
WORKDIR /home/futag/Futag/
RUN pip install futag-llvm/python-package/futag-2.0.0.tar.gz
RUN pip install futag-llvm/python-package/futag-2.0.1.tar.gz
RUN pip install -r futag-llvm/python-package/requirements.txt

USER futag
Expand Down
33 changes: 17 additions & 16 deletions src/clang/include/Futag/Basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,23 @@ typedef enum {
typedef enum {
F_BUILTIN, // 0: All basic types: int, float, double,...
F_CSTRING, // 1: char *, const char *
F_CXXSTRING, // 2: char *, const char *
F_ENUM, // 3
F_ARRAY, // 4
F_VOIDP, // 5
F_QUALIFIER, // 6: const, volatile, and restrict qualifiers
F_POINTER, // 7
F_STRUCT, // 8
F_UNION, // 9
F_CLASS, // 10
F_INCOMPLETE, // 11
F_FUNCTION, // 12
F_INPUT_CXXFILE, // 13
F_OUTPUT_CXXFILE, // 14
F_CXXFILE, // 15
F_CFILE, // 16
F_UNKNOWN, // 17
F_WSTRING, // 2: char *, const char *
F_CXXSTRING, // 3: char *, const char *
F_ENUM, // 4
F_ARRAY, // 5
F_VOIDP, // 6
F_QUALIFIER, // 7: const, volatile, and restrict qualifiers
F_POINTER, // 8
F_STRUCT, // 9
F_UNION, // 10
F_CLASS, // 11
F_INCOMPLETE, // 12
F_FUNCTION, // 13
F_INPUT_CXXFILE, // 14
F_OUTPUT_CXXFILE, // 15
F_CXXFILE, // 16
F_CFILE, // 17
F_UNKNOWN, // 18
} FutagGenType;

typedef struct {
Expand Down
13 changes: 10 additions & 3 deletions src/clang/lib/Futag/Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* a tool of ISP RAS *
************************************************
*
* @version 1.3.1
* @date 2023-01-29
* @version 2.0.1
* @date 2023-04-05
*
* @copyright This file is distributed under the GPL v3 license
*
Expand Down Expand Up @@ -400,11 +400,13 @@ vector<GenTypeInfo> getGenType(QualType type) {
if (std::find(str_types.begin(), str_types.end(),
type.getCanonicalType().getAsString()) !=
str_types.end()) {
gen_list.gen_type = FutagGenType::F_CSTRING;
gen_list.base_type_name = "char *";
if (std::find(wchar_str_types.begin(), wchar_str_types.end(),
type.getCanonicalType().getAsString()) !=
wchar_str_types.end()) {
gen_list.base_type_name = "wchar_t *";
gen_list.gen_type = FutagGenType::F_WSTRING;
}
if (std::find(const_str_types.begin(), const_str_types.end(),
type.getCanonicalType().getAsString()) !=
Expand All @@ -416,9 +418,10 @@ vector<GenTypeInfo> getGenType(QualType type) {
if (canonical_type.getAsString() == "const wchar_t *" ||
canonical_type.getAsString() == "const wchar_t *const") {
gen_list.base_type_name = "wchar_t *";
gen_list.gen_type = FutagGenType::F_WSTRING;
}
}
gen_list.gen_type = FutagGenType::F_CSTRING;

result.insert(result.begin(), gen_list);
return result;
}
Expand Down Expand Up @@ -584,6 +587,10 @@ std::string GetFutagGenTypeFromIdx(FutagGenType idx) {
return "_CSTRING";
break;

case FutagGenType::F_WSTRING:
return "_WSTRING";
break;

case FutagGenType::F_CXXSTRING:
return "_CXXSTRING";
break;
Expand Down
3 changes: 3 additions & 0 deletions src/clang/lib/Futag/ConsumerFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ void SearchVarDeclInBlock(
futag::FutagPath &curr_analyzed_path, // for checking reverse match
std::vector<FutagInitVarDeclCallExpr> &init_calls,
const json &analysis_jdb) {

MatchFinder Finder;

const auto matched_binaryoperator =
binaryOperator(
isAssignmentOperator(),
Expand All @@ -321,6 +323,7 @@ void SearchVarDeclInBlock(
declRefExpr(to(functionDecl().bind("DefTargetFunctionCall")))
.bind("DefDeclRefExpr"))))
.bind("DefFutagBinOpArg");

const auto matched_vardecl =
varDecl(hasName(iter_arg.value),
hasDescendant(declRefExpr(to(functionDecl().bind(
Expand Down
2 changes: 1 addition & 1 deletion src/python/futag-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This python package is for building library, generating and compiling fuzz-drive
## 1. Install

```bash
pip install dist/futag-1.3.1.tar.gz
pip install dist/futag-2.0.1.tar.gz
```

## 2. Preprocessor
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/python/futag-package/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = futag
version = 2.0.0
version = 2.0.1
author = Futag-team of ISP RAS
author_email = thientcgithub@gmail.com
description = Python package of Futag
Expand Down
2 changes: 1 addition & 1 deletion src/python/futag-package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='futag',
version='2.0.0',
version='2.0.1',
author='Futag-team of ISP RAS',
author_email='thientcgithub@gmail.com',
packages=['futag'],
Expand Down
4 changes: 2 additions & 2 deletions src/python/futag-package/src/futag.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: futag
Version: 2.0.0
Version: 2.0.1
Summary: Futag tools for creating fuzz targets of software library
Home-page: https://github.com/ispras/Futag/tree/main/src/python/futag-package
Author: Futag-team of ISP RAS
Expand Down Expand Up @@ -36,7 +36,7 @@ This python package is for building library, generating and compiling fuzz-drive
## 1. Install

```bash
pip install dist/futag-1.3.1.tar.gz
pip install dist/futag-2.0.1.tar.gz
```

## 2. Preprocessor
Expand Down
7 changes: 3 additions & 4 deletions src/python/futag-package/src/futag/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,9 @@ def fuzz(self, extra_param: str = ""):
for x in [t for t in dir.glob("*.out") if t.is_file()]:
print("\n-- [Futag] FUZZING driver: " + x.stem + "... \n")
my_env = os.environ.copy()
if self.leak:
my_env["ASAN_OPTIONS"] = "allocator_may_return_null=1"
else:
my_env["ASAN_OPTIONS"] = "detect_leaks=0:allocator_may_return_null=1"
if not self.leak:
my_env["ASAN_OPTIONS"] = "detect_leaks=0"

my_env["ASAN_SYMBOLIZER_PATH"] = symbolizer.as_posix()
if self.coverage:
my_env["LLVM_PROFILE_FILE"] = x.as_posix() + ".profraw"
Expand Down
Loading

0 comments on commit 69c2971

Please sign in to comment.