From c91ccc8b4eab2a42a2e6b903f62838a1cadc6f7c Mon Sep 17 00:00:00 2001 From: LoveSy Date: Thu, 4 Nov 2021 11:53:50 +0800 Subject: [PATCH] Fix UB on dtb `operator==` of string_view will create a tmp `string_view`. It's an UB if the `const char *` is a nullptr. `fdt_get_name` however will return a nullptr. --- native/jni/magiskboot/dtb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/jni/magiskboot/dtb.cpp b/native/jni/magiskboot/dtb.cpp index 3853e980a..c35948cda 100644 --- a/native/jni/magiskboot/dtb.cpp +++ b/native/jni/magiskboot/dtb.cpp @@ -82,7 +82,7 @@ static void print_node(const void *fdt, int node = 0, int depth = 0) { } static int find_fstab(const void *fdt, int node = 0) { - if (fdt_get_name(fdt, node, nullptr) == "fstab"sv) + if (auto name = fdt_get_name(fdt, node, nullptr); name && name == "fstab"sv) return node; int child; fdt_for_each_subnode(child, fdt, node) { @@ -142,7 +142,7 @@ static bool dtb_patch(const char *file) { int node; // Patch the chosen node for bootargs fdt_for_each_subnode(node, fdt, 0) { - if (fdt_get_name(fdt, node, nullptr) != "chosen"sv) + if (auto name = fdt_get_name(fdt, node, nullptr); !name || name != "chosen"sv) continue; int len; if (auto value = fdt_getprop(fdt, node, "bootargs", &len)) {