aboutsummaryrefslogtreecommitdiff
path: root/riscv/sim.cc
diff options
context:
space:
mode:
authorRupert Swarbrick <rswarbrick@gmail.com>2022-02-22 02:58:18 +0000
committerGitHub <noreply@github.com>2022-02-21 18:58:18 -0800
commit5ba63a44706173b556b8d5632872b39a09d7f16d (patch)
tree4609ef25700b475092c6bd7e68aa9ee27f8ff040 /riscv/sim.cc
parentaa72b99944faaa6439ed3e6744e5abbaa91562de (diff)
downloadspike-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/sim.cc')
-rw-r--r--riscv/sim.cc6
1 files changed, 3 insertions, 3 deletions
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);
}