diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2016-03-30 17:03:07 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2016-03-30 17:03:07 +0000 |
commit | 8a891c953ee03b10d6175b3444f72adfd03e8de8 (patch) | |
tree | 6e36967772a4c0f2be8dbce095b078c01302341f | |
parent | 628cce6b418a9791aa4990f00511a2f5d4303252 (diff) |
The change to make mkstemp(3) require at least 6 trailing Xs broke
rdistd for directories that do not exist on the destination. Calling
mkstemp(3) twice with the same format (filled in by the first
mkstemp(3) call) is bogus so call chkparent() *before* mkstemp(3)
instead of only on error. This costs an extra lstat(2) in the case
where the directory already exists but simplifies the code and
doesn't rely on undefined behavior (namely, the state of the template
when mkstemp fails). OK tim@
-rw-r--r-- | usr.bin/rdistd/server.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index 23188f9225a..df86bf06681 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.40 2015/12/22 08:48:39 mmcc Exp $ */ +/* $OpenBSD: server.c,v 1.41 2016/03/30 17:03:06 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -750,12 +750,9 @@ recvfile(char *new, opt_t opts, int mode, char *owner, char *group, /* * Create temporary file */ - if ((f = mkstemp(new)) < 0) { - if (errno != ENOENT || chkparent(new, opts) < 0 || - (f = mkstemp(new)) < 0) { - error("%s: create failed: %s", new, SYSERR); - return; - } + if (chkparent(new, opts) < 0 || (f = mkstemp(new)) < 0) { + error("%s: create failed: %s", new, SYSERR); + return; } /* @@ -1161,13 +1158,10 @@ recvlink(char *new, opt_t opts, int mode, off_t size) /* * Make new symlink using a temporary name */ - if (mktemp(new) == NULL || symlink(dbuf, new) < 0) { - if (errno != ENOENT || chkparent(new, opts) < 0 || - mktemp(new) == NULL || symlink(dbuf, new) < 0) { - error("%s -> %s: symlink failed: %s", new, dbuf, - SYSERR); - return; - } + if (chkparent(new, opts) < 0 || mktemp(new) == NULL || + symlink(dbuf, new) < 0) { + error("%s -> %s: symlink failed: %s", new, dbuf, SYSERR); + return; } /* |