Skip to content

Commit

Permalink
lib: safe_mkstemp*() didn't always truncate prefix back to original o…
Browse files Browse the repository at this point in the history
…n failure.

This caused repeated safe_mkstemp*() calls with the same prefix to keep
increasing its size. It probably didn't really break anything (unless it was
called enough many times to reach 255 filename length), but the filenames
were still confusingly ugly.
  • Loading branch information
sirainen committed Sep 15, 2016
1 parent 6d2e2c7 commit 033e315
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/safe-mkstemp.c
Expand Up @@ -65,6 +65,7 @@ safe_mkstemp_full(string_t *prefix, mode_t mode, uid_t uid, gid_t gid,
}
i_close_fd(&fd);
i_unlink(str_c(prefix));
str_truncate(prefix, prefix_len);
return -1;
}
return fd;
Expand All @@ -83,13 +84,23 @@ int safe_mkstemp_group(string_t *prefix, mode_t mode,

int safe_mkstemp_hostpid(string_t *prefix, mode_t mode, uid_t uid, gid_t gid)
{
size_t orig_prefix_len = str_len(prefix);
int fd;

str_printfa(prefix, "%s.%s.", my_hostname, my_pid);
return safe_mkstemp(prefix, mode, uid, gid);
if ((fd = safe_mkstemp(prefix, mode, uid, gid)) == -1)
str_truncate(prefix, orig_prefix_len);
return fd;
}

int safe_mkstemp_hostpid_group(string_t *prefix, mode_t mode,
gid_t gid, const char *gid_origin)
{
size_t orig_prefix_len = str_len(prefix);
int fd;

str_printfa(prefix, "%s.%s.", my_hostname, my_pid);
return safe_mkstemp_group(prefix, mode, gid, gid_origin);
if ((fd = safe_mkstemp_group(prefix, mode, gid, gid_origin)) == -1)
str_truncate(prefix, orig_prefix_len);
return fd;
}

0 comments on commit 033e315

Please sign in to comment.