summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-12-14 22:47:38 +0000
committerderaadt <deraadt@openbsd.org>1996-12-14 22:47:38 +0000
commite1cbcf7fd035a55ac694a5f2010aaef42e7855f1 (patch)
tree85eca5df24004f606977674e96c961f4491decd3
parentAdd Theo's changes to yppush, some very ugly debugging code is now gone. -moj (diff)
downloadwireguard-openbsd-e1cbcf7fd035a55ac694a5f2010aaef42e7855f1.tar.xz
wireguard-openbsd-e1cbcf7fd035a55ac694a5f2010aaef42e7855f1.zip
solve /tmp-style race spotted by bitblt
-rw-r--r--libexec/ftpd/ftpd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 6376883dc97..2815072a654 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftpd.c,v 1.26 1996/12/07 09:00:22 bitblt Exp $ */
+/* $OpenBSD: ftpd.c,v 1.27 1996/12/14 22:47:38 deraadt Exp $ */
/* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */
/*
@@ -1816,7 +1816,7 @@ gunique(local)
{
static char new[MAXPATHLEN];
struct stat st;
- int count, len;
+ int count, len, fd;
char *cp;
cp = strrchr(local, '/');
@@ -1837,8 +1837,11 @@ gunique(local)
*cp++ = '.';
for (count = 1; count < 100; count++) {
(void)snprintf(cp, sizeof(new) - (cp - new), "%d", count);
- if (stat(new, &st) < 0)
- return (new);
+ fd = open(new, O_RDWR|O_CREAT|O_EXCL, 0666);
+ if (fd == -1)
+ continue;
+ close(fd);
+ return (new);
}
reply(452, "Unique file name cannot be created.");
return (NULL);