]> git.ozlabs.org Git - petitboot/commitdiff
discover: Use snprintf() when building sysparam path
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Mon, 9 Nov 2015 03:59:41 +0000 (14:59 +1100)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Thu, 17 Dec 2015 03:51:46 +0000 (14:51 +1100)
Fixes Coverity defects #30481 and #30482

Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover/platform-powerpc.c

index ce4eb8199ed33d01570e14aac57ce924fba3bb90..2480b8d29129fd27da866dc02e869c248c00b8b2 100644 (file)
@@ -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) {