From e474d1d54a7c0e1cf9ee67a09cd013b9c936cc5e Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 30 Oct 2023 09:11:26 -0700 Subject: [PATCH] target/riscv: Prevent dump_field() reading uninitialized memory Change-Id: I9ef8f2c2e9a824aa6595e8f20682c968ae5aed72 Signed-off-by: Tim Newsome --- src/target/riscv/riscv-013.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 5697ad296..04c39a11f 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -354,6 +354,8 @@ static unsigned int decode_dm(char *text, unsigned int address, unsigned int dat context, data); } } + if (text) + text[0] = '\0'; return 0; } @@ -361,8 +363,11 @@ static unsigned int decode_dmi(struct target *target, char *text, unsigned int a unsigned int data) { dm013_info_t *dm = get_dm(target); - if (!dm) + if (!dm) { + if (text) + text[0] = '\0'; return 0; + } return decode_dm(text, address - dm->base, data); }