From 22d44fff279a13a42fd5efe2f341b82be66e9779 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 6 Jun 2026 02:41:16 +0000 Subject: [PATCH] test fuzzer --- src/frontend_common/config.cpp | 18 +++++------ tools/fuzzsettings.cpp | 56 ++++++++++++++++++++++++++++++++++ tools/fuzzsettings.sh | 12 ++++++++ 3 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 tools/fuzzsettings.cpp create mode 100755 tools/fuzzsettings.sh diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp index 599c2a0ce4..809021fad0 100644 --- a/src/frontend_common/config.cpp +++ b/src/frontend_common/config.cpp @@ -245,13 +245,14 @@ void Config::ReadMotionTouchValues() { Settings::TouchFromButtonMap map; map.name = ReadStringSetting(std::string("name"), std::string("default")); - - const int num_touch_maps = BeginArray(std::string("entries")); - map.buttons.reserve(num_touch_maps); - for (int j = 0; j < num_touch_maps; j++) { - SetArrayIndex(j); - std::string touch_mapping = ReadStringSetting(std::string("bind")); - map.buttons.emplace_back(std::move(touch_mapping)); + int const num_touch_maps = BeginArray(std::string("entries")); + if (num_touch_maps > 0) { + map.buttons.reserve(num_touch_maps); + for (int j = 0; j < num_touch_maps; j++) { + SetArrayIndex(j); + std::string touch_mapping = ReadStringSetting(std::string("bind")); + map.buttons.emplace_back(std::move(touch_mapping)); + } } EndArray(); // entries Settings::values.touch_from_button_maps.emplace_back(std::move(map)); @@ -1049,8 +1050,7 @@ std::string Config::GetFullKey(const std::string& key, bool skipArrayIndex) { int Config::BeginArray(const std::string& array) { array_stack.push_back(ConfigArray{AdjustKey(array), 0, 0}); - const int size = config->GetLongValue(GetSection().c_str(), - GetFullKey(std::string("size"), true).c_str(), 0); + const int size = config->GetLongValue(GetSection().c_str(), GetFullKey(std::string("size"), true).c_str(), 0); array_stack.back().size = size; return size; } diff --git a/tools/fuzzsettings.cpp b/tools/fuzzsettings.cpp new file mode 100644 index 0000000000..2d62f3302f --- /dev/null +++ b/tools/fuzzsettings.cpp @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + std::srand(unsigned(std::time(nullptr))); + + FILE *fp = std::fopen(argv[1], "rt"); + if (fp) { + char line[BUFSIZ]; + while (std::fgets(line, sizeof(line), fp)) { + if (line[0] == '[') { + std::printf("%s", line); + } else if (std::isspace(line[0])) { + std::printf("%s", line); + } else { + char *p = std::strchr(line, '='); + if (std::strstr(line, "\\default") == nullptr) { + // not default + *p = '\0'; + std::string new_line{line}; + std::string value{p + 1}; + if (value == "true" || value == "false") { + new_line += std::string{} + "=TreufLAlse857874FJJakshjryiu475" + '\n'; + } else if (std::isdigit(value[0])) { + if (new_line == "size" || std::strstr(new_line.c_str(), "entries\\size") != nullptr) { + new_line += "=-1\n"; + } else { + new_line += '=' + std::to_string(int(std::rand())) + '\n'; + } + } else { + std::string_view const cset{"03832///1/1/.1/1./1./1./1.1/.1194573290uwmgjouidyhiomHMNIODASJK,POF MSHDVLJPOIuksdtpsunmghns"}; + std::string rst{"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}; + for (size_t i = 0; i < rst.size(); ++i) + rst[i] = cset[std::rand() % cset.size()]; + + //new_line += "=\"" + rst + "\""; + new_line += "=" + value; + } + std::printf("%s", new_line.c_str()); + } else { + std::printf("%s", line); + } + } + } + std::fclose(fp); + } + return 0; +} diff --git a/tools/fuzzsettings.sh b/tools/fuzzsettings.sh new file mode 100755 index 0000000000..7cf613dc3d --- /dev/null +++ b/tools/fuzzsettings.sh @@ -0,0 +1,12 @@ +#!/bin/sh -ex + +# SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +# SPDX-License-Identifier: GPL-3.0-or-later + +ROOTDIR=$(CDPATH='' cd -- "$(dirname -- "$0")/" && pwd) + +touch "$2" + +c++ "$ROOTDIR/fuzzsettings.cpp" -o fuzzsettings +./fuzzsettings "$1" >"$2" +rm fuzzsettings