* [PATCH 1/1] riscv: add NULL check before calling strlen in the riscv cpu's get_desc()
@ 2024-05-06 9:10 Hanyuan Zhao
2024-05-14 10:07 ` Leo Liang
0 siblings, 1 reply; 2+ messages in thread
From: Hanyuan Zhao @ 2024-05-06 9:10 UTC (permalink / raw)
To: u-boot; +Cc: Leo, Bin Meng, Hanyuan Zhao, Hanyuan Zhao
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>
---
drivers/cpu/riscv_cpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c
index 9b1950efe0..d39a943cb8 100644
--- a/drivers/cpu/riscv_cpu.c
+++ b/drivers/cpu/riscv_cpu.c
@@ -24,7 +24,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);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] riscv: add NULL check before calling strlen in the riscv cpu's get_desc()
2024-05-06 9:10 [PATCH 1/1] riscv: add NULL check before calling strlen in the riscv cpu's get_desc() Hanyuan Zhao
@ 2024-05-14 10:07 ` Leo Liang
0 siblings, 0 replies; 2+ messages in thread
From: Leo Liang @ 2024-05-14 10:07 UTC (permalink / raw)
To: Hanyuan Zhao; +Cc: u-boot, Bin Meng, Hanyuan Zhao
On Mon, May 06, 2024 at 05:10:06PM +0800, Hanyuan Zhao wrote:
> 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>
> ---
> drivers/cpu/riscv_cpu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-14 10:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-06 9:10 [PATCH 1/1] riscv: add NULL check before calling strlen in the riscv cpu's get_desc() Hanyuan Zhao
2024-05-14 10:07 ` Leo Liang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.