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/sim.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'riscv/sim.cc') diff --git a/riscv/sim.cc b/riscv/sim.cc index a0f13ae..ad7e45b 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -136,8 +136,8 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, } //handle mmu-type - char mmu_type[256] = ""; - rc = fdt_parse_mmu_type(fdt, cpu_offset, mmu_type); + const char *mmu_type; + rc = fdt_parse_mmu_type(fdt, cpu_offset, &mmu_type); if (rc == 0) { procs[cpu_idx]->set_mmu_capability(IMPL_MMU_SBARE); if (strncmp(mmu_type, "riscv,sv32", strlen("riscv,sv32")) == 0) { @@ -151,7 +151,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch, } else { std::cerr << "core (" << hartids.size() - << ") doesn't have valid 'mmu-type'" + << ") has an invalid 'mmu-type': " << mmu_type << ").\n"; exit(1); } -- cgit v1.1