1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 04:33:53 +00:00
CLI11/fuzz/fuzzApp.hpp
Philip Top 0a615f854d
fix: issue found by fuzzing (#846)
* Add the beginnings of a fuzzing system for CLI11.  This commit adds the fuzzing code, a simple test, and two fixes to issues(seg faults) found by the initial round of fuzzing.  It also adds a few tests and coverage issues uncovered in the process of developing the fuzz tests. As a side effect adjusts some of the azure tests to specify the vmImage which was being changed on azure.

* update license to match rest of code base

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-03-09 15:02:49 -05:00

93 lines
2.2 KiB
C++

// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#ifdef CLI11_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif
#include <atomic>
#include <iostream>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace CLI {
class intWrapper64 {
public:
intWrapper64() = default;
explicit intWrapper64(int64_t v) : val(v){};
CLI11_NODISCARD int64_t value() const { return val; }
private:
int64_t val{0};
};
class doubleWrapper {
public:
doubleWrapper() = default;
explicit doubleWrapper(double v) : val(v){};
CLI11_NODISCARD double value() const { return val; }
private:
double val{0.0};
};
class FuzzApp {
public:
FuzzApp() = default;
std::shared_ptr<CLI::App> generateApp();
int32_t val32{0};
int16_t val16{0};
int8_t val8{0};
int64_t val64{0};
uint32_t uval32{0};
uint16_t uval16{0};
uint8_t uval8{0};
uint64_t uval64{0};
std::atomic<int64_t> atomicval64{0};
std::atomic<uint64_t> atomicuval64{0};
double v1{0};
float v2{0};
std::vector<double> vv1{};
std::vector<std::string> vstr{};
std::vector<std::vector<double>> vecvecd{};
std::vector<std::vector<std::string>> vvs{};
std::optional<double> od1{};
std::optional<std::string> ods{};
std::pair<double, std::string> p1{};
std::pair<std::vector<double>, std::string> p2{};
std::tuple<int64_t, uint16_t, std::optional<double>> t1{};
std::tuple<std::tuple<std::tuple<std::string, double, std::vector<int>>, std::string, double>,
std::vector<int>,
std::optional<std::string>>
tcomplex{};
std::tuple<std::tuple<std::tuple<std::string, double, std::vector<int>>, std::string, double>,
std::vector<int>,
std::optional<std::string>>
tcomplex2{};
std::string_view vstrv = "";
bool flag1{false};
int flagCnt{0};
std::atomic<bool> flagAtomic{false};
intWrapper64 iwrap{0};
doubleWrapper dwrap{0.0};
};
} // namespace CLI