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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <cstdint>
25#include <string>
26#include <memory>
27
29#include <richio.h>
30#include <board_item.h>
31
32#include "fuzz_init.h"
33#include <pcbnew_settings.h>
34#include <mock_pgm_base.h>
36
37extern "C" int LLVMFuzzerInitialize( int* argc, char*** argv )
38{
39 fuzz_init( argc, argv );
41
44
45 return 0;
46}
47
48extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
49 std::string input(reinterpret_cast<const char*>(Data), Size);
50 STRING_LINE_READER reader(input, "fuzz");
51
52 auto callback = [](wxString, int, wxString, wxString) { return true; };
53
54 // We need to handle exceptions as the parser throws on invalid input
55 try {
56 PCB_IO_KICAD_SEXPR_PARSER parser(&reader, nullptr, callback);
57 std::unique_ptr<BOARD_ITEM> item(parser.Parse());
58 } catch (...) {
59 }
60
61 return 0;
62}
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:129
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:226
int fuzz_init(int *argc, char ***argv)
Initialize wxWidgets and KiCad PGM_BASE for fuzzing.
Definition fuzz_init.cpp:32
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.
Definition pgm_base.cpp:946