[PATCH] ACPICA: Handle memory allocation error

From: Aleksandr Mishin
Date: Fri Apr 12 2024 - 06:39:32 EST


In acpi_db_add_to_history() acpi_os_allocate() may return NULL
in case of memory allocation error. This will lead to NULL pointer
dereference.
Fix this bug by adding NULL return check.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 995751025572 ("ACPICA: Linuxize: Export debugger files to Linux")
Signed-off-by: Aleksandr Mishin <amishin@xxxxxxxxxx>
---
drivers/acpi/acpica/dbhistry.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/acpi/acpica/dbhistry.c b/drivers/acpi/acpica/dbhistry.c
index e874c1dddefa..8366631d457f 100644
--- a/drivers/acpi/acpica/dbhistry.c
+++ b/drivers/acpi/acpica/dbhistry.c
@@ -69,6 +69,8 @@ void acpi_db_add_to_history(char *command_line)
acpi_gbl_history_buffer[acpi_gbl_next_history_index].command =
acpi_os_allocate(cmd_len + 1);
}
+ if (!acpi_gbl_history_buffer[acpi_gbl_next_history_index].command)
+ return;

strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command,
command_line);
--
2.30.2