• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 
14 #include <fstream>
15 #include <iostream>
16 
17 #include "diskio.h"
18 #include "mbr.h"
19 #include "gpt.h"
20 
21 #include <fuzzer/FuzzedDataProvider.h>
22 
23 std::ofstream silence("/dev/null");
24 
LLVMFuzzerInitialize(int *,char ***)25 extern "C" int LLVMFuzzerInitialize(int *, char ***) {
26     std::cout.rdbuf(silence.rdbuf());
27     std::cerr.rdbuf(silence.rdbuf());
28     return 0;
29 }
30 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32     DiskIO disk;
33     disk.OpenForRead(static_cast<const unsigned char*>(data), size);
34 
35     BasicMBRData mbrData;
36     mbrData.ReadMBRData(&disk);
37 
38     GPTData gptData;
39     gptData.SetDisk(disk);
40     gptData.LoadPartitions("/dev/does_not_exist");
41 
42     return 0;
43 }
44