fix build warnings 22/225822/1
authorjeon <jhyuni.kang@samsung.com>
Tue, 25 Feb 2020 01:00:04 +0000 (10:00 +0900)
committerjeon <jhyuni.kang@samsung.com>
Tue, 25 Feb 2020 01:00:09 +0000 (10:00 +0900)
  - warning: specified bound depends on the length of the
    source argument
  - using source argument's length in strncat, strncpy
    can cause string overflow
  - so instead of use source length, to use snprintf

Change-Id: Ica4ece26165670ac968725d8a69a3431e9d9aa5a

src/lib/pepper/utils-file.c
src/samples/sample-client.c

index 2fe9272..50f0929 100644 (file)
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <linux/limits.h>
+#include <stdio.h>
 
 static int
 set_cloexec_or_close(int fd)
@@ -110,8 +111,7 @@ pepper_create_anonymous_file(off_t size)
                return -1;
        }
 
-       strncpy(name, path, strlen(path) + 1);
-       strncat(name, template, sizeof(template));
+       snprintf(name, strlen(path) + sizeof(template), "%s%s", path, template);
 
        free(path);
        path = NULL;
index 144b475..0a6f51a 100644 (file)
@@ -222,8 +222,7 @@ os_create_anonymous_file(off_t size)
        if (!name)
                return -1;
 
-       strncpy(name, path, strlen(path) + 1);
-       strncat(name, template, sizeof(template));
+       snprintf(name, strlen(path) + sizeof(template), "%s%s", path, template);
 
        fd = create_tmpfile_cloexec(name);