aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-09 05:57:56 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-05-09 05:57:56 +0000
commit79f8f1960c76a7eb2b2925f0b9bd4f2aa976b84b (patch)
treeec5c0bb7c8cd851f7bbd96cfd486b82b878ec8ec
parent38a87275f03f6e6ad596789b1e64a6c4b3bb95ee (diff)
parent8c0093a65c32c969e8f5dfbfcaa26332a0cef936 (diff)
downloaddtc-android13-frc-documentsui-release.tar.gz
Snap for 8558685 from 8c0093a65c32c969e8f5dfbfcaa26332a0cef936 to tm-frc-documentsui-releaset_frc_doc_330543000t_frc_doc_330443060t_frc_doc_330443000android13-frc-documentsui-release
Change-Id: I0a744719b6eb82f492cce8f23e025ee470333562
-rw-r--r--fuzzing/Android.bp15
-rw-r--r--fuzzing/libfdt_fuzzer.cpp42
2 files changed, 57 insertions, 0 deletions
diff --git a/fuzzing/Android.bp b/fuzzing/Android.bp
new file mode 100644
index 0000000..ddda130
--- /dev/null
+++ b/fuzzing/Android.bp
@@ -0,0 +1,15 @@
+// Copyright 2022 The Android Open Source Project
+package {
+ default_applicable_licenses: ["external_dtc_license"],
+}
+
+cc_fuzz {
+ name: "libfdt_fuzzer",
+ srcs: [
+ "libfdt_fuzzer.cpp",
+ ],
+ static_libs: [
+ "libfdt",
+ ],
+ host_supported: true,
+}
diff --git a/fuzzing/libfdt_fuzzer.cpp b/fuzzing/libfdt_fuzzer.cpp
new file mode 100644
index 0000000..4a0b1fc
--- /dev/null
+++ b/fuzzing/libfdt_fuzzer.cpp
@@ -0,0 +1,42 @@
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libfdt.h"
+#include "libfdt_env.h"
+
+void walk_device_tree(const void *device_tree, int parent_node) {
+ int len = 0;
+ const char *node_name = fdt_get_name(device_tree, parent_node, &len);
+ if (node_name != NULL) {
+ // avoid clang complaining about unused variable node_name and force
+ // ASan to validate string pointer in strlen call.
+ assert(strlen(node_name) == len);
+ }
+
+ uint32_t phandle = fdt_get_phandle(device_tree, parent_node);
+ if (phandle != 0) {
+ assert(parent_node == fdt_node_offset_by_phandle(device_tree, phandle));
+ }
+
+ // recursively walk the node's children
+ for (int node = fdt_first_subnode(device_tree, parent_node); node >= 0;
+ node = fdt_next_subnode(device_tree, node)) {
+ walk_device_tree(device_tree, node);
+ }
+}
+
+// Information on device tree is available in external/dtc/Documentation/
+// folder.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ // Non-zero return values are reserved for future use.
+ if (size < FDT_V17_SIZE) return 0;
+
+ if (fdt_check_header(data) != 0) return 0;
+
+ int root_node_offset = 0;
+ walk_device_tree(data, root_node_offset);
+
+ return 0;
+} \ No newline at end of file