[PATCH] acpi: add null check on calls to get_space_id_name()
Colin King
colin.king at canonical.com
Tue Jan 19 09:53:52 UTC 2021
From: Colin Ian King <colin.king at canonical.com>
A null can be potentially returned from get_space_id_name() if the id is
out of range, so add a null check. Also don't call the function multiple
times but use a temporary char * pointer to stash the result of the call.
Addresses-Coverity: ("Dereference null return")
Fixes: ffea02df09d3 ("acpi: add fwts_acpi_space_id_check to check GAS adrress space ids")
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_acpi_tables.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 6ad1bf77..d832a65c 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -1668,17 +1668,23 @@ void fwts_acpi_space_id_check(
va_start(ap, num_type);
for (i = 0; i < num_type; i++) {
+ const char *id_name;
+
must_be = va_arg(ap, int);
if (actual == must_be) {
matched = true;
break;
}
- length += strlen(get_space_id_name(must_be));
+ id_name = get_space_id_name(must_be);
+ if (!id_name)
+ continue;
+
+ length += strlen(id_name);
if (length > 255)
continue;
- strncat(must_be_id, get_space_id_name(must_be), strlen(get_space_id_name(must_be)));
+ strncat(must_be_id, id_name, strlen(id_name));
if (i < num_type - 2)
strncat(must_be_id, ", ", 3);
else if (i == num_type - 2)
--
2.29.2
More information about the fwts-devel
mailing list