[PATCH 02/11] discover: Use snprintf() when building sysparam path

Samuel Mendoza-Jonas sam.mj at au1.ibm.com
Thu Nov 12 15:34:32 AEDT 2015


Fixes Coverity defects #30481 and #30482

Signed-off-by: Samuel Mendoza-Jonas <sam.mj at au1.ibm.com>
---
 discover/platform-powerpc.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c
index 2a02d75..b1092c5 100644
--- a/discover/platform-powerpc.c
+++ b/discover/platform-powerpc.c
@@ -759,9 +759,8 @@ static int read_bootdev_sysparam(const char *name, uint8_t *val)
 	char path[50];
 	int fd, rc;
 
-	strcpy(path, sysparams_dir);
-	assert(strlen(name) < sizeof(path) - strlen(path));
-	strcat(path, name);
+	assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+	snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
@@ -795,9 +794,8 @@ static int write_bootdev_sysparam(const char *name, uint8_t val)
 	char path[50];
 	int fd, rc;
 
-	strcpy(path, sysparams_dir);
-	assert(strlen(name) < sizeof(path) - strlen(path));
-	strcat(path, name);
+	assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+	snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
 
 	fd = open(path, O_WRONLY);
 	if (fd < 0) {
-- 
2.6.2



More information about the Petitboot mailing list