[PATCH] opal: ensure fdt_node_path buffer is null terminated

Colin King colin.king at canonical.com
Tue Sep 6 08:20:13 UTC 2016


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

Ensure the fdt_node_path is terminated with a '\0', fixes warnings
found in static analysis by Coverity Scan

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/opal/mtd_info.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/opal/mtd_info.c b/src/opal/mtd_info.c
index 4aac9b9..5f08e9c 100644
--- a/src/opal/mtd_info.c
+++ b/src/opal/mtd_info.c
@@ -165,7 +165,7 @@ int mtd_dev_query(fwts_framework *fw, char *mtd_devnode)
 
 static int mtd_info_test1(fwts_framework *fw)
 {
-	char fdt_node_path[PATH_MAX];
+	char fdt_node_path[PATH_MAX + 1];
 	int count, i, fd;
 	ssize_t bytes = 0, bytes_read = 0;
 	struct dirent **namelist;
@@ -181,7 +181,7 @@ static int mtd_info_test1(fwts_framework *fw)
 			FDT_FLASH_PATH);
 		return FWTS_ERROR;
 	}
-	bytes_read = read(fd, fdt_node_path, sizeof(fdt_node_path));
+	bytes_read = read(fd, fdt_node_path, PATH_MAX);
 	if (bytes_read < 0) {
 		fwts_failed(fw, LOG_LEVEL_CRITICAL,
 			"OPAL MTD Info",
@@ -193,6 +193,7 @@ static int mtd_info_test1(fwts_framework *fw)
 		return FWTS_ERROR;
 	}
 	close(fd);
+	fdt_node_path[PATH_MAX] = '\0';
 	fwts_log_info(fw, "MTD Info validated FDT of '%s'.",
 			fdt_node_path);
 
-- 
2.9.3




More information about the fwts-devel mailing list