diff options
| author | Carlos López <carlos.lopezr4096@gmail.com> | 2024-08-01 14:48:11 +0200 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2024-08-02 08:53:20 +0530 |
| commit | cb0f4757fc2904cbf579e34feba891a5878625c5 (patch) | |
| tree | d6c034ffb404dc898a8d9905b7af94029e658ae2 | |
| parent | baf6a75e3f967aa8b65a20963bd9ae21975ba75a (diff) | |
| download | opensbi-cb0f4757fc2904cbf579e34feba891a5878625c5.tar.gz opensbi-cb0f4757fc2904cbf579e34feba891a5878625c5.zip | |
lib: sbi: fwft: fix incorrect size passed to sbi_zalloc()
The fwt_hart_state struct inciludes a flexible array member, so its
allocation size will be that of the struct itself, plus that of each
of the members in the array. When calculating this size, instead of
taking the size of the struct, the size of a pointer to it was taken,
which is incorrect. Luckily, this happenned to not produce memory
corruption because the size of the non-flexible members of the struct
is the same as the size of a pointer.
Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
| -rw-r--r-- | lib/sbi/sbi_fwft.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/sbi/sbi_fwft.c b/lib/sbi/sbi_fwft.c index f1ae9159..ef881ef5 100644 --- a/lib/sbi/sbi_fwft.c +++ b/lib/sbi/sbi_fwft.c @@ -251,7 +251,7 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot) fhs = fwft_get_hart_state_ptr(scratch); if (!fhs) { - fhs = sbi_zalloc(sizeof(fhs) + array_size(features) * sizeof(struct fwft_config)); + fhs = sbi_zalloc(sizeof(*fhs) + array_size(features) * sizeof(struct fwft_config)); if (!fhs) return SBI_ENOMEM; |
