- 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
#include <fcntl.h>
#include <unistd.h>
#include <linux/limits.h>
+#include <stdio.h>
static int
set_cloexec_or_close(int fd)
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;
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);