Skip to content

Commit

Permalink
riscv: add NULL check before calling strlen in the riscv cpu's get_de…
Browse files Browse the repository at this point in the history
…sc()

Without the NULL check, if the devicetree that u-boot loads does not have a
compatible property then a store access fault will be raised and force the
machine to reset, due to the NULL pointer we passed to strlen. This commit
adds this check and will return -ENOSPC to indicate the get_desc failed.

Signed-off-by: Hanyuan Zhao <[email protected]>
Reviewed-by: Leo Yu-Chi Liang <[email protected]>
  • Loading branch information
gtxzsxxk authored and Leo Yu-Chi Liang committed May 14, 2024
1 parent c8ffd13 commit 9578e74
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/cpu/riscv_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int riscv_cpu_get_desc(const struct udevice *dev, char *buf, int size)
const char *cpu;

cpu = dev_read_string(dev, "compatible");
if (size < (strlen(cpu) + 1))
if (!cpu || size < (strlen(cpu) + 1))
return -ENOSPC;

strcpy(buf, cpu);
Expand Down

0 comments on commit 9578e74

Please sign in to comment.