commit 2a8575caa345795b2b831ab19dc90cdc7d9fb168
parent c6ab8675d8927ff887f37f89282176b40fd303b0
Author: Naveen Narayanan zerous <zerous@nocebo.space>
Date: Sat, 23 Dec 2017 19:39:08 +0300
fix snprintf
Diffstat:
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/pass.c b/pass.c
@@ -145,13 +145,14 @@ getuserid(char *u)
void
mkdirp(const char *tp)
{
- char *i;
+ char *i, t[PATH_MAX];
int r;
mode_t mode = S_IRWXU;
+ memcpy(t, file, strlen(file) + 1);
while ((i = strchr(tp, '/'))) {
*i = '\0';
- snprintf(file, sizeof(file), "%s/%s", file, tp);
+ snprintf(file, sizeof(file), "%s/%s", t, tp);
printf("mkdir %s\n", file);
if ((r = mkdir(file, mode)) == -1) {
if (errno == EEXIST)
@@ -186,8 +187,8 @@ insert(char *item)
filename = basename(item);
mkdirp(item);
-
- snprintf(file, sizeof(file), "%s/%s", file, filename);
+ memcpy(t, file, strlen(file) + 1);
+ snprintf(file, sizeof(file), "%s/%s", t, filename);
snprintf(t, sizeof(t), "%s.gpg", file);
if ((fp = fopen(t, "r"))) {
@@ -247,7 +248,7 @@ insert(char *item)
fin = fopen(file, "r");
memcpy(t, file, strlen(file) + 1);
- snprintf(file, sizeof(file), "%s.gpg", file);
+ snprintf(file, sizeof(file), "%s.gpg", t);
fout = fopen(file, "w");
gpgerr = gpgme_data_new_from_stream(&in, fin);