KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fuzz_pcb_sexpr.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <cstdint>
21#include <string>
22#include <memory>
23
25#include <richio.h>
26#include <board_item.h>
27
28#include "fuzz_init.h"
29#include <pcbnew_settings.h>
30#include <mock_pgm_base.h>
32
33extern "C" int LLVMFuzzerInitialize( int* argc, char*** argv )
34{
35 fuzz_init( argc, argv );
37
40
41 return 0;
42}
43
44extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
45 std::string input(reinterpret_cast<const char*>(Data), Size);
46 STRING_LINE_READER reader(input, "fuzz");
47
48 auto callback = [](wxString, int, wxString, wxString) { return true; };
49
50 // We need to handle exceptions as the parser throws on invalid input
51 try {
52 PCB_IO_KICAD_SEXPR_PARSER parser(&reader, nullptr, callback);
53 std::unique_ptr<BOARD_ITEM> item(parser.Parse());
54 } catch (...) {
55 }
56
57 return 0;
58}
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:222
int fuzz_init(int *argc, char ***argv)
Initialize wxWidgets and KiCad PGM_BASE for fuzzing.
Definition fuzz_init.cpp:28
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
int LLVMFuzzerInitialize(int *argc, char ***argv)
Pcbnew s-expression file format parser definition.
PGM_BASE & Pgm()
The global program "get" accessor.