diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2008-05-13 02:13:47 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2008-05-13 02:13:47 +0000 |
commit | 86314c41f65dc5fa6ef8719498f95fa47497d5bd (patch) | |
tree | 35289fffe4cf7f7614b61b5ae7b6fc68933c4924 /usr.bin | |
parent | ca2cb43ab4a7462e45950e56d79a902d9413a14e (diff) |
Change a mktemp(3) to mkstemp(3), preventing a race condition.
Improve error checking.
OK okan@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rdistd/server.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index da8d447c986..b56df199e1e 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.17 2006/02/01 19:06:24 otto Exp $ */ +/* $OpenBSD: server.c,v 1.18 2008/05/13 02:13:46 ray Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -36,7 +36,7 @@ static char RCSid[] __attribute__((__unused__)) = "$From: server.c,v 1.10 1999/08/04 15:57:33 christos Exp $"; #else static char RCSid[] __attribute__((__unused__)) = -"$OpenBSD: server.c,v 1.17 2006/02/01 19:06:24 otto Exp $"; +"$OpenBSD: server.c,v 1.18 2008/05/13 02:13:46 ray Exp $"; #endif static char sccsid[] __attribute__((__unused__)) = @@ -74,7 +74,7 @@ static void docmdspecial(void); static void query(char *); static int chkparent(char *, opt_t); static char *savetarget(char *, opt_t); -static void recvfile(char *, opt_t, int, char *, char *, time_t, time_t, off_t); +static void recvfile(char *, int, opt_t, int, char *, char *, time_t, time_t, off_t); static void recvdir(opt_t, int, char *, char *); static void recvlink(char *, opt_t, int, off_t); static void hardlink(char *); @@ -784,28 +784,16 @@ savetarget(char *file, opt_t opts) * Receive a file */ static void -recvfile(char *new, opt_t opts, int mode, char *owner, char *group, - time_t mtime, time_t atime, off_t size) +recvfile(char *new, int f, opt_t opts, int mode, char *owner, + char *group, time_t mtime, time_t atime, off_t size) { - int f, wrerr, olderrno; + int wrerr, olderrno; off_t i; char *cp; char *savefile = NULL; static struct stat statbuff; /* - * Create temporary file - */ - if ((f = open(new, O_CREAT|O_EXCL|O_WRONLY, mode)) < 0) { - if (errno != ENOENT || chkparent(new, opts) < 0 || - (f = open(new, O_CREAT|O_EXCL|O_WRONLY, mode)) < 0) { - error("%s: create failed: %s", new, SYSERR); - (void) unlink(new); - return; - } - } - - /* * Receive the file itself */ ack(); @@ -1402,7 +1390,7 @@ setconfig(char *cmd) static void recvit(char *cmd, int type) { - int mode; + int f, mode; opt_t opts; off_t size; time_t mtime, atime; @@ -1528,7 +1516,10 @@ recvit(char *cmd, int type) tempname); *file = '/'; } - (void) mktemp(new); + if ((f = mkstemp(new)) == -1) { + error("%s: create failed: %s", new, SYSERR); + return; + } } /* @@ -1575,7 +1566,7 @@ recvit(char *cmd, int type) break; case S_IFREG: - recvfile(new, opts, mode, owner, group, mtime, atime, size); + recvfile(new, f, opts, mode, owner, group, mtime, atime, size); break; default: |