From 5ba63a44706173b556b8d5632872b39a09d7f16d Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Tue, 22 Feb 2022 02:58:18 +0000 Subject: Avoid an unnecessary strcpy (#925) We don't actually know that the field in the DTB points at a string that's less than 256 bytes long, I don't think, so this could probably cause a buffer overflow on the stack. Anyway, it turns out that there's no need to copy anything anyway, so let's just update a char** instead. --- riscv/dts.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'riscv/dts.cc') diff --git a/riscv/dts.cc b/riscv/dts.cc index 46000d8..09accf9 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -3,6 +3,7 @@ #include "dts.h" #include "libfdt.h" #include "platform.h" +#include #include #include #include @@ -306,8 +307,10 @@ int fdt_parse_pmp_alignment(void *fdt, int cpu_offset, reg_t *pmp_align) return 0; } -int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type) +int fdt_parse_mmu_type(void *fdt, int cpu_offset, const char **mmu_type) { + assert(mmu_type); + int len, rc; const void *prop; @@ -318,7 +321,7 @@ int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type) if (!prop || !len) return -EINVAL; - strcpy(mmu_type, (char *)prop); + *mmu_type = (const char *)prop; return 0; } -- cgit v1.1