riscv: add NULL check before calling strlen in the riscv cpu's get_desc()
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 <zhaohy22@mails.tsinghua.edu.cn> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
This commit is contained in:
committed by
Leo Yu-Chi Liang
parent
c8ffd1356d
commit
9578e74571
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user