From a69bd56c05384f45ff4f853054229372dcfa5a65 Mon Sep 17 00:00:00 2001 From: Yuanyuan Zhao Date: Thu, 18 Nov 2021 09:44:17 +0800 Subject: [PATCH] dm: fix add check for malloc result Add check for malloc result to madt pointer. Tracked-On: #6769 Signed-off-by: Yuanyuan Zhao --- devicemodel/hw/platform/acpi/acpi_parser.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/devicemodel/hw/platform/acpi/acpi_parser.c b/devicemodel/hw/platform/acpi/acpi_parser.c index afe5ad31f..c29add4eb 100644 --- a/devicemodel/hw/platform/acpi/acpi_parser.c +++ b/devicemodel/hw/platform/acpi/acpi_parser.c @@ -117,6 +117,11 @@ int parse_madt(void) } madt = (struct acpi_table_madt *)malloc(file_state.st_size); + if (madt == NULL) { + pr_err("Failed to malloc %d bytes for MADT!\n", file_state.st_size); + close(fd); + return -1; + } size = read(fd, madt, file_state.st_size); if (size == file_state.st_size) { ret = local_parse_madt(madt);