diff options
author | Rupert Swarbrick <rswarbrick@gmail.com> | 2022-02-22 02:58:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 18:58:18 -0800 |
commit | 5ba63a44706173b556b8d5632872b39a09d7f16d (patch) | |
tree | 4609ef25700b475092c6bd7e68aa9ee27f8ff040 /riscv/dts.cc | |
parent | aa72b99944faaa6439ed3e6744e5abbaa91562de (diff) | |
download | spike-5ba63a44706173b556b8d5632872b39a09d7f16d.zip spike-5ba63a44706173b556b8d5632872b39a09d7f16d.tar.gz spike-5ba63a44706173b556b8d5632872b39a09d7f16d.tar.bz2 |
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.
Diffstat (limited to 'riscv/dts.cc')
-rw-r--r-- | riscv/dts.cc | 7 |
1 files changed, 5 insertions, 2 deletions
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 <cassert> #include <iostream> #include <sstream> #include <signal.h> @@ -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; } |