[PATCH] lib: fwts_acpi_tables: fix warnings found by clang scan-build

Colin King colin.king at canonical.com
Tue Feb 16 23:36:08 UTC 2016


From: Colin Ian King <colin.king at canonical.com>

scan build detected the possibility of a zero sized read, causing ptr
to be left NULL and/or size to be 0, so check for these and bail out
with an error if this is detected.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_acpi_tables.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 59fd4ba..281ce77 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -757,6 +757,9 @@ static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length)
 		size += n;
 	}
 
+	if (!ptr || !size)
+		goto err_no_data;
+
 	/*
 	 *  ..and copy table into a 32 bit memory space buffer
 	 */
@@ -770,6 +773,7 @@ static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length)
 
 err:
 	free(ptr);
+err_no_data:
 	*length = 0;
 	return NULL;
 }
-- 
2.7.0




More information about the fwts-devel mailing list