From 48df6b8485fdbcb922a46e8239c009f66e4c6a60 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 31 Oct 2021 11:46:56 -0700 Subject: [PATCH] Use memmem instead of strstr It might not be null terminated --- native/jni/magiskboot/dtb.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/native/jni/magiskboot/dtb.cpp b/native/jni/magiskboot/dtb.cpp index e37d4656f..3853e980a 100644 --- a/native/jni/magiskboot/dtb.cpp +++ b/native/jni/magiskboot/dtb.cpp @@ -1,15 +1,13 @@ #include #include #include +#include #include #include "magiskboot.hpp" #include "dtb.hpp" #include "format.hpp" -extern "C" { -#include -} using namespace std; @@ -147,14 +145,14 @@ static bool dtb_patch(const char *file) { if (fdt_get_name(fdt, node, nullptr) != "chosen"sv) continue; int len; - if (char *value = (char *) fdt_getprop(fdt, node, "bootargs", &len)) { - if (char *skip = strstr(value, "skip_initramfs")) { + if (auto value = fdt_getprop(fdt, node, "bootargs", &len)) { + if (void *skip = memmem(value, len, "skip_initramfs", 14)) { fprintf(stderr, "Patch [skip_initramfs] -> [want_initramfs]\n"); - // Don't use strcpy, we do NOT want it null terminated memcpy(skip, "want", 4); patched = true; } } + break; } if (int fstab = find_fstab(fdt); fstab >= 0) { fdt_for_each_subnode(node, fdt, fstab) {