summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2016-03-30 17:03:06 +0000
committermillert <millert@openbsd.org>2016-03-30 17:03:06 +0000
commitb3282e78f90ae5ce6671617ddb84a66e1a9afc63 (patch)
treeb5fd3efffb25e26715d24624137f2b79827b0347
parentBetter support for alphas without all IEEE-mode instructions (diff)
downloadwireguard-openbsd-b3282e78f90ae5ce6671617ddb84a66e1a9afc63.tar.xz
wireguard-openbsd-b3282e78f90ae5ce6671617ddb84a66e1a9afc63.zip
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.c22
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;
}
/*