diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-21 14:50:07 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-21 14:50:07 +0000 |
commit | 5c0b98fffa808aea530374a0cd08454ba9f1c444 (patch) | |
tree | 2782d4c888b85855ffe36724ad02bff0e57d9dbc | |
parent | 5d939ab5a49835fbbb985a078e2ef679c268d0e0 (diff) | |
parent | c2d8370656ab17db24cd5f9b969210487e0b4324 (diff) | |
download | gptfdisk-android12-mainline-cellbroadcast-release.tar.gz |
Snap for 7478067 from c2d8370656ab17db24cd5f9b969210487e0b4324 to mainline-cellbroadcast-releaseandroid-mainline-12.0.0_r86android-mainline-12.0.0_r71android-mainline-12.0.0_r7android-mainline-12.0.0_r60android-mainline-12.0.0_r43android-mainline-12.0.0_r24android-mainline-12.0.0_r116android-mainline-12.0.0_r101android12-mainline-cellbroadcast-release
Change-Id: Iae7dbbd9ff15d545e088be657b7180c62e94bbcf
-rw-r--r-- | Android.bp | 108 | ||||
-rw-r--r-- | METADATA | 1 | ||||
l--------- | NOTICE | 1 | ||||
-rw-r--r-- | diskio-heap.cc | 86 | ||||
-rw-r--r-- | diskio.h | 8 | ||||
-rw-r--r-- | fuzzer/Android.bp | 31 | ||||
-rw-r--r-- | fuzzer/corpus/typical.bin | bin | 0 -> 36864 bytes | |||
-rw-r--r-- | fuzzer/libgptf_fuzzer.cc | 43 | ||||
-rw-r--r-- | gpt.cc | 5 | ||||
-rw-r--r-- | gpt.h | 1 |
10 files changed, 260 insertions, 24 deletions
@@ -1,33 +1,42 @@ -cc_binary { - name: "sgdisk", - host_supported: true, +package { + default_applicable_licenses: ["external_gptfdisk_license"], +} - srcs: [ - "sgdisk.cc", - "gptcl.cc", - "crc32.cc", - "support.cc", - "guid.cc", - "gptpart.cc", - "mbrpart.cc", - "basicmbr.cc", - "mbr.cc", - "gpt.cc", - "bsd.cc", - "parttypes.cc", - "attributes.cc", - "diskio.cc", - "diskio-unix.cc", - "android_popt.cc", +// Added automatically by a large-scale-change that took the approach of +// 'apply every license found to every target'. While this makes sure we respect +// every license restriction, it may not be entirely correct. +// +// e.g. GPL in an MIT project might only apply to the contrib/ directory. +// +// Please consider splitting the single license below into multiple licenses, +// taking care not to lose any license_kind information, and overriding the +// default license using the 'licenses: [...]' property on targets as needed. +// +// For unused files, consider creating a 'fileGroup' with "//visibility:private" +// to attach the license to, and including a comment whether the files may be +// used in the current project. +// See: http://go/android-license-faq +license { + name: "external_gptfdisk_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-GPL", + "SPDX-license-identifier-GPL-2.0", + "SPDX-license-identifier-LGPL", + ], + license_text: [ + "COPYING", ], +} + +cc_defaults { + name: "gptfdisk_default_flags", cflags: [ "-Wno-unused-parameter", "-Wno-pragma-pack", "-Werror", + "-fPIC", ], - - shared_libs: ["libext2_uuid"], - target: { darwin: { cflags: [ @@ -37,3 +46,56 @@ cc_binary { }, }, } + +cc_binary { + name: "sgdisk", + defaults: ["gptfdisk_default_flags"], + host_supported: true, + + srcs: [ + "sgdisk.cc", + ], + + shared_libs: ["libext2_uuid"], + static_libs: ["libgptf"], +} + +lib_common_srcs = [ + "gptcl.cc", + "crc32.cc", + "support.cc", + "guid.cc", + "gptpart.cc", + "mbrpart.cc", + "basicmbr.cc", + "mbr.cc", + "gpt.cc", + "bsd.cc", + "parttypes.cc", + "attributes.cc", + "diskio.cc", + "android_popt.cc", +] + +cc_library_static { + name: "libgptf", + defaults: ["gptfdisk_default_flags"], + host_supported: true, + + export_include_dirs: ["."], + srcs: lib_common_srcs + ["diskio-unix.cc"], + + shared_libs: ["libext2_uuid"], +} + +cc_library_static { + name: "libgptf_fuzzer_lib", + defaults: ["gptfdisk_default_flags"], + host_supported: true, + + export_include_dirs: ["."], + srcs: lib_common_srcs + ["diskio-heap.cc"], + cflags: ["-DENABLE_HEAP_DISKIO"], + + shared_libs: ["libext2_uuid"], +} @@ -10,6 +10,7 @@ third_party { value: "https://git.code.sf.net/p/gptfdisk/code" } version: "d292ff36a3b350115835c62462911c3d8721704f" + license_type: RESTRICTED last_upgrade_date { year: 2020 month: 2 @@ -1 +0,0 @@ -LICENSE
\ No newline at end of file diff --git a/diskio-heap.cc b/diskio-heap.cc new file mode 100644 index 0000000..3129113 --- /dev/null +++ b/diskio-heap.cc @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <algorithm> + +#include "diskio.h" + +using namespace std; + +int DiskIO::OpenForRead(const unsigned char* data, size_t size) { + this->data = data; + this->size = size; + this->off = 0; + this->isOpen = 1; + this->openForWrite = 0; + return 1; +} + +void DiskIO::MakeRealName(void) { + realFilename = userFilename; +} + +int DiskIO::OpenForRead(void) { + return 1; +} + +int DiskIO::OpenForWrite(void) { + return 1; +} + +void DiskIO::Close(void) { +} + +int DiskIO::GetBlockSize(void) { + return 512; +} + +int DiskIO::GetPhysBlockSize(void) { + return 512; +} + +uint32_t DiskIO::GetNumHeads(void) { + return 255; +} + +uint32_t DiskIO::GetNumSecsPerTrack(void) { + return 63; +} + +int DiskIO::DiskSync(void) { + return 1; +} + +int DiskIO::Seek(uint64_t sector) { + off_t off = sector * GetBlockSize(); + if (off >= this->size) { + return 0; + } else { + this->off = off; + return 1; + } +} + +int DiskIO::Read(void* buffer, int numBytes) { + int actualBytes = std::min(static_cast<int>(this->size - this->off), numBytes); + memcpy(buffer, this->data + this->off, actualBytes); + return actualBytes; +} + +int DiskIO::Write(void*, int) { + return 0; +} + +uint64_t DiskIO::DiskSize(int *) { + return this->size / GetBlockSize(); +} @@ -57,11 +57,19 @@ class DiskIO { #else int fd; #endif +#ifdef ENABLE_HEAP_DISKIO + const unsigned char* data; + size_t size; + off_t off; +#endif public: DiskIO(void); ~DiskIO(void); void MakeRealName(void); +#ifdef ENABLE_HEAP_DISKIO + int OpenForRead(const unsigned char* data, size_t size); +#endif int OpenForRead(const string & filename); int OpenForRead(void); int OpenForWrite(const string & filename); diff --git a/fuzzer/Android.bp b/fuzzer/Android.bp new file mode 100644 index 0000000..5f4a18b --- /dev/null +++ b/fuzzer/Android.bp @@ -0,0 +1,31 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "external_gptfdisk_license" + // to get the below license kinds: + // SPDX-license-identifier-GPL-2.0 + default_applicable_licenses: ["external_gptfdisk_license"], +} + +cc_fuzz { + name: "libgptf_fuzzer", + srcs: ["libgptf_fuzzer.cc"], + cflags: ["-DENABLE_HEAP_DISKIO"], + host_supported: true, + corpus: ["corpus/*"], + static_libs: ["libgmock"], + target: { + android: { + static_libs: [ + "libgptf_fuzzer_lib", + "libext2_uuid", + ], + }, + host: { + static_libs: [ + "libgptf_fuzzer_lib", + "libext2_uuid", + ], + }, + }, +} diff --git a/fuzzer/corpus/typical.bin b/fuzzer/corpus/typical.bin Binary files differnew file mode 100644 index 0000000..666506e --- /dev/null +++ b/fuzzer/corpus/typical.bin diff --git a/fuzzer/libgptf_fuzzer.cc b/fuzzer/libgptf_fuzzer.cc new file mode 100644 index 0000000..688167a --- /dev/null +++ b/fuzzer/libgptf_fuzzer.cc @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <fstream> +#include <iostream> + +#include "diskio.h" +#include "mbr.h" +#include "gpt.h" + +#include <fuzzer/FuzzedDataProvider.h> + +std::ofstream silence("/dev/null"); + +extern "C" int LLVMFuzzerInitialize(int *, char ***) { + std::cout.rdbuf(silence.rdbuf()); + std::cerr.rdbuf(silence.rdbuf()); + return 0; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + DiskIO disk; + disk.OpenForRead(static_cast<const unsigned char*>(data), size); + + BasicMBRData mbrData; + mbrData.ReadMBRData(&disk); + + GPTData gptData; + gptData.SetDisk(disk); + gptData.LoadPartitions("/dev/does_not_exist"); + + return 0; +} @@ -780,6 +780,11 @@ int GPTData::SetDisk(const string & deviceFilename) { return allOK; } // GPTData::SetDisk() +int GPTData::SetDisk(const DiskIO & disk) { + myDisk = disk; + return 1; +} // GPTData::SetDisk() + // Scan for partition data. This function loads the MBR data (regular MBR or // protective MBR) and loads BSD disklabel data (which is probably invalid). // It also looks for APM data, forces a load of GPT data, and summarizes @@ -112,6 +112,7 @@ public: // Load or save data from/to disk int SetDisk(const string & deviceFilename); + int SetDisk(const DiskIO & disk); DiskIO* GetDisk(void) {return &myDisk;} int LoadMBR(const string & f) {return protectiveMBR.ReadMBRData(f);} int WriteProtectiveMBR(void) {return protectiveMBR.WriteMBRData(&myDisk);} |