diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2007-06-12 11:11:09 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2007-06-12 11:11:09 +0000 |
commit | 866c4cd318922e8cb8dd0ff20e1c5683119a6460 (patch) | |
tree | 173c6c58e927aaf9f61223949434e37225ce51e6 | |
parent | 5083cfc638017059b7f2b3a8aa51094f3a5a5c8e (diff) |
fix slave exit value when a control master goes away without passing the
full exit status by ensuring that the slave reads a full int. bz#1261
reported by frekko AT gmail.com; ok markus@ dtucker@
-rw-r--r-- | usr.bin/ssh/ssh.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c index 5e30321f0bc..71ae9509c02 100644 --- a/usr.bin/ssh/ssh.c +++ b/usr.bin/ssh/ssh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.295 2007/01/03 03:01:40 stevesk Exp $ */ +/* $OpenBSD: ssh.c,v 1.296 2007/06/12 11:11:08 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -1433,25 +1433,28 @@ control_client(const char *path) /* Stick around until the controlee closes the client_fd */ exitval = 0; - for (;!control_client_terminate;) { - r = read(sock, &exitval, sizeof(exitval)); + for (i = 0; !control_client_terminate && i < (int)sizeof(exitval);) { + r = read(sock, (char *)&exitval + i, sizeof(exitval) - i); if (r == 0) { debug2("Received EOF from master"); break; } - if (r > 0) - debug2("Received exit status from master %d", exitval); if (r == -1 && errno != EINTR) fatal("%s: read %s", __func__, strerror(errno)); + i += r; } - - if (control_client_terminate) - debug2("Exiting on signal %d", control_client_terminate); - close(sock); - leave_raw_mode(); + if (control_client_terminate) { + debug2("Exiting on signal %d", control_client_terminate); + exitval = 255; + } else if (i < (int)sizeof(exitval)) { + debug2("Control master terminated unexpectedly"); + exitval = 255; + } else + debug2("Received exit status from master %d", exitval); + if (tty_flag && options.log_level != SYSLOG_LEVEL_QUIET) fprintf(stderr, "Connection to master closed.\r\n"); |