summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuoyanlifusu <[email protected]>2026-09-29 19:55:16 +0800
committerRbb666 <[email protected]>2026-10-15 13:50:46 +0800
commit5d1fb66d1397608662ca810b781ae54133dcab07 (patch)
treecf01e0178dcae7085fdbd5d11d64bff15bd41c2d
parent40a302d5546a795731d68d7a1b3173e36dd22345 (diff)
[drivers][ofw] Fix phandle hash buffer overflow
-rw-r--r--components/drivers/ofw/base.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/components/drivers/ofw/base.c b/components/drivers/ofw/base.c
index 1b0e761be3..d50b57693a 100644
--- a/components/drivers/ofw/base.c
+++ b/components/drivers/ofw/base.c
@@ -43,7 +43,7 @@ rt_err_t ofw_phandle_hash_reset(rt_phandle min, rt_phandle max)
if (max > _phandle_range[1])
{
- rt_size_t size = sizeof(*_phandle_hash) * (max - min);
+ rt_size_t size = sizeof(*_phandle_hash) * (max - min + 1);
if (!_phandle_hash)
{
@@ -55,9 +55,11 @@ rt_err_t ofw_phandle_hash_reset(rt_phandle min, rt_phandle max)
if (hash_ptr)
{
+ rt_size_t old_min = _phandle_range[0];
rt_size_t old_max = _phandle_range[1];
+ rt_size_t old_count = old_max - old_min + 1;
- rt_memset(&hash_ptr[old_max], 0, sizeof(_phandle_hash) * (max - old_max));
+ rt_memset(&hash_ptr[old_count], 0, size - old_count * sizeof(*_phandle_hash));
}
}
}