The allocation of board_local_name is followed by a test on board_info
instead of on the newly allocated pointer, so an allocation failure is
never detected and the first strcat() writes through a NULL pointer.
The same test is also placed after the allocation, so returning early
because board_info is NULL leaks the buffer, while every other exit from
the function goes through the error: label and frees it.
Test board_info before allocating anything and check the calloc() result
on its own.
Fixes: 52ff1626cf4c ("xilinx: common: Enabling generic function for DT
reselection")
Signed-off-by: Sriram Sriram <[email protected]>
---
Changes in v2:
- New patch. Replaces v1 1/2 ("board: xilinx: Use strlcat() in
board_name_decode()"), which is dropped in favour of Pranav Tilak's
patch for the same heap overflow.
board/xilinx/common/board.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c
index f45b879736e..9ea5f46c9a8 100644
--- a/board/xilinx/common/board.c
+++ b/board/xilinx/common/board.c
@@ -573,10 +573,13 @@ char * __maybe_unused __weak board_name_decode(void)
struct xilinx_board_description *desc;
int i, id;
- board_local_name = calloc(1, MAX_NAME_LENGTH);
if (!board_info)
return NULL;
+ board_local_name = calloc(1, MAX_NAME_LENGTH);
+ if (!board_local_name)
+ return NULL;
+
for (id = 0; id <= highest_id; id++) {
desc = &board_info[id];
--
2.49.0