Merge "ANDROID: fuzz: Only check valid phandles"

This commit is contained in:
Treehugger Robot 2022-09-09 16:44:45 +00:00 committed by Gerrit Code Review
commit 91b7c8d942

View file

@ -55,6 +55,9 @@ static void check_mem(const void *mem, size_t len) {
#endif #endif
} }
static bool phandle_is_valid(uint32_t phandle) {
return phandle != 0 && phandle != UINT32_MAX;
}
static void walk_device_tree(const void *device_tree, int parent_node) { static void walk_device_tree(const void *device_tree, int parent_node) {
int len = 0; int len = 0;
@ -64,8 +67,9 @@ static void walk_device_tree(const void *device_tree, int parent_node) {
} }
uint32_t phandle = fdt_get_phandle(device_tree, parent_node); uint32_t phandle = fdt_get_phandle(device_tree, parent_node);
if (phandle != 0) { if (phandle_is_valid(phandle)) {
assert(parent_node == fdt_node_offset_by_phandle(device_tree, phandle)); int node = fdt_node_offset_by_phandle(device_tree, phandle);
assert(node >= 0); // it should at least find parent_node
} }
// recursively walk the node's children // recursively walk the node's children