mirror of
https://github.com/red0124/ssp.git
synced 2025-01-22 20:55:18 +01:00
parent
f5b750dd93
commit
1b9a01f787
7
.github/fuzz/makefile
vendored
Normal file
7
.github/fuzz/makefile
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
EXE=ssp_fuzz
|
||||
|
||||
all:
|
||||
clang++ ${CXXFLAGS} ssp_fuzz.cpp -fsanitize=fuzzer -std=c++17 -o ${EXE}
|
||||
|
||||
run:
|
||||
./${EXE} -max_total_time=900
|
81
.github/fuzz/ssp_fuzz.cpp
vendored
Normal file
81
.github/fuzz/ssp_fuzz.cpp
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
#include "../../ssp.hpp"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
template <typename... Ts>
|
||||
void test_ssp_file_mode(const uint8_t* data, size_t size,
|
||||
std::string delim = ss::default_delimiter) {
|
||||
std::string file_name = std::filesystem::temp_directory_path().append(
|
||||
"ss_fuzzer" + std::to_string(getpid()) + ".csv");
|
||||
FILE* file = std::fopen(file_name.c_str(), "wb");
|
||||
if (!file) {
|
||||
std::exit(1);
|
||||
}
|
||||
std::fwrite(data, size, 1, file);
|
||||
std::fclose(file);
|
||||
|
||||
ss::parser<Ts...> p{file_name.c_str(), delim};
|
||||
while (!p.eof()) {
|
||||
try {
|
||||
const auto& [s0, s1] =
|
||||
p.template get_next<std::string, std::string>();
|
||||
if (s0.size() == 10000) {
|
||||
std::cout << s0.size() << std::endl;
|
||||
}
|
||||
} catch (ss::exception& e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
std::remove(file_name.c_str());
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void test_ssp_buffer_mode(const uint8_t* data, size_t size,
|
||||
std::string delim = ss::default_delimiter) {
|
||||
ss::parser<Ts...> p{(const char*)data, size, delim};
|
||||
while (!p.eof()) {
|
||||
try {
|
||||
const auto& [s0, s1] =
|
||||
p.template get_next<std::string, std::string>();
|
||||
if (s0.size() == 10000) {
|
||||
std::cout << s0.size() << std::endl;
|
||||
}
|
||||
} catch (ss::exception& e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void test_ssp(const uint8_t* data, size_t size) {
|
||||
test_ssp_file_mode<Ts...>(data, size);
|
||||
test_ssp_file_mode<Ts..., ss::throw_on_error>(data, size);
|
||||
|
||||
test_ssp_file_mode<Ts...>(data, size, ":::");
|
||||
test_ssp_file_mode<Ts..., ss::throw_on_error>(data, size, ":::");
|
||||
|
||||
test_ssp_buffer_mode<Ts...>(data, size);
|
||||
test_ssp_buffer_mode<Ts..., ss::throw_on_error>(data, size);
|
||||
|
||||
test_ssp_buffer_mode<Ts...>(data, size, ":::");
|
||||
test_ssp_buffer_mode<Ts..., ss::throw_on_error>(data, size, ":::");
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
using escape = ss::escape<'\\'>;
|
||||
using quote = ss::quote<'"'>;
|
||||
using trim = ss::trim<' ', '\t'>;
|
||||
using multiline_r = ss::multiline_restricted<5>;
|
||||
|
||||
test_ssp<>(data, size);
|
||||
test_ssp<escape>(data, size);
|
||||
test_ssp<quote>(data, size);
|
||||
test_ssp<trim>(data, size);
|
||||
test_ssp<quote, escape>(data, size);
|
||||
test_ssp<escape, quote, multiline_r, trim>(data, size);
|
||||
test_ssp<escape, quote, multiline_r, trim, ss::ignore_empty>(data, size);
|
||||
|
||||
return 0;
|
||||
}
|
43
.github/workflows/fuzz.yml
vendored
Normal file
43
.github/workflows/fuzz.yml
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
name: fuzz-ci
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- feature/**
|
||||
- improvement/**
|
||||
- bugfix/**
|
||||
|
||||
jobs:
|
||||
clang_tests:
|
||||
if: >-
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
! contains(toJSON(github.event.commits.*.message), '[skip github]')
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
name: "Fuzzing"
|
||||
|
||||
container:
|
||||
image: silkeh/clang:15
|
||||
options: -v /usr/local:/host_usr_local
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Build
|
||||
working-directory: .github/fuzz
|
||||
run: make
|
||||
|
||||
- name: Run
|
||||
working-directory: .github/fuzz
|
||||
run: make run
|
@ -9,6 +9,7 @@
|
||||
|
||||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
|
||||
[![coverage](https://coveralls.io/repos/github/red0124/ssp/badge.svg?branch=master)](https://coveralls.io/github/red0124/ssp?branch=master)
|
||||
[![fuzz](https://github.com/red0124/ssp/workflows/fuzz-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/fuzz.yml)
|
||||
[![single-header](https://github.com/red0124/ssp/workflows/single-header-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/single-header.yml)
|
||||
[![ubuntu-latest-gcc](https://github.com/red0124/ssp/workflows/ubuntu-latest-gcc-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/ubuntu-latest-gcc.yml)
|
||||
[![ubuntu-latest-clang](https://github.com/red0124/ssp/workflows/ubuntu-latest-clang-ci/badge.svg)](https://github.com/red0124/ssp/actions/workflows/ubuntu-latest-clang.yml)
|
||||
|
Loading…
Reference in New Issue
Block a user