summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2019-06-03 15:37:49 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2019-06-03 15:37:49 +0000
commit25a53227bd6800662b0f35b6ae4c0f0e7ad58500 (patch)
treee59501dc05278a7bf08e8395c67b308212ff4f73 /usr.bin
parentcc7e1ddd344fd45adf155f8345c924b601bb10aa (diff)
Don't close the socket in rsync_socket() itself but after calling it.
Fixes a corner case where the socket was closed twice, reported by Hiltjo Posthuma. ok deraadt@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/rsync/main.c15
-rw-r--r--usr.bin/rsync/socket.c3
2 files changed, 6 insertions, 12 deletions
diff --git a/usr.bin/rsync/main.c b/usr.bin/rsync/main.c
index 4f6137420b4..5e39f012c37 100644
--- a/usr.bin/rsync/main.c
+++ b/usr.bin/rsync/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.46 2019/05/28 18:20:30 deraadt Exp $ */
+/* $Id: main.c,v 1.47 2019/06/03 15:37:48 naddy Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -428,8 +428,10 @@ main(int argc, char *argv[])
if (fargs->remote && opts.ssh_prog == NULL) {
assert(fargs->mode == FARGS_RECEIVER);
- if ((rc = rsync_connect(&opts, &sd, fargs)) == 0)
+ if ((rc = rsync_connect(&opts, &sd, fargs)) == 0) {
rc = rsync_socket(&opts, sd, fargs);
+ close(sd);
+ }
exit(rc);
}
@@ -484,14 +486,7 @@ main(int argc, char *argv[])
break;
}
- /*
- * If the client has an error and exits, the server may be
- * sitting around waiting to get data while we waitpid().
- * So close the connection here so that they don't hang.
- */
-
- if (rc)
- close(fds[0]);
+ close(fds[0]);
if (waitpid(child, &st, 0) == -1)
err(1, "waitpid");
diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c
index 1a0844f1313..740a19918f9 100644
--- a/usr.bin/rsync/socket.c
+++ b/usr.bin/rsync/socket.c
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.24 2019/05/08 21:30:11 benno Exp $ */
+/* $Id: socket.c,v 1.25 2019/06/03 15:37:48 naddy Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -455,6 +455,5 @@ rsync_socket(const struct opts *opts, int sd, const struct fargs *f)
rc = 0;
out:
free(args);
- close(sd);
return rc;
}