forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinGetYamlFuzzing.cpp
More file actions
58 lines (46 loc) · 1.6 KB
/
Copy pathWinGetYamlFuzzing.cpp
File metadata and controls
58 lines (46 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include <cstdint>
#include <optional>
#include <winget/ManifestYamlParser.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t * data, size_t size)
{
std::string input{ reinterpret_cast<const char*>(data), size };
try
{
AppInstaller::Manifest::Manifest manifest = AppInstaller::Manifest::YamlParser::Create(input);
}
catch (...) {}
return 0;
}
#ifndef WINGET_DISABLE_FOR_FUZZING
#include <AppInstallerStrings.h>
// Emulate libFuzzer main by just sending all files in the corpus (last arg) to the fuzzer.
int main(int argc, char** argv)
{
if (argc <= 1)
{
return 1;
}
std::filesystem::path corpus = argv[argc - 1];
if (std::filesystem::is_directory(corpus))
{
for (auto& file : std::filesystem::directory_iterator{ corpus })
{
if (!file.is_directory())
{
std::ifstream stream{ file.path(), std::ios_base::in | std::ios_base::binary };
std::string contents = AppInstaller::Utility::ReadEntireStream(stream);
LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(contents.data()), contents.size());
}
}
}
else
{
std::ifstream stream{ corpus, std::ios_base::in | std::ios_base::binary };
std::string contents = AppInstaller::Utility::ReadEntireStream(stream);
LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t*>(contents.data()), contents.size());
}
return 0;
}
#endif