diff options
author | 2003-11-17 09:45:39 +0000 | |
---|---|---|
committer | 2003-11-17 09:45:39 +0000 | |
commit | 3c7791bdf7c946885132c3bd4f08dc262b7f2acd (patch) | |
tree | cf2942af5e87dbec456bda7f0e8c72e6d7529018 /usr.bin/ssh/msg.c | |
parent | sync (diff) | |
download | wireguard-openbsd-3c7791bdf7c946885132c3bd4f08dc262b7f2acd.tar.xz wireguard-openbsd-3c7791bdf7c946885132c3bd4f08dc262b7f2acd.zip |
return error on msg send/receive failure (rather than fatal); ok markus@
Diffstat (limited to 'usr.bin/ssh/msg.c')
-rw-r--r-- | usr.bin/ssh/msg.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/usr.bin/ssh/msg.c b/usr.bin/ssh/msg.c index 6a806c3f5a1..30bc3f10763 100644 --- a/usr.bin/ssh/msg.c +++ b/usr.bin/ssh/msg.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: msg.c,v 1.6 2003/06/28 16:23:06 deraadt Exp $"); +RCSID("$OpenBSD: msg.c,v 1.7 2003/11/17 09:45:39 djm Exp $"); #include "buffer.h" #include "getput.h" @@ -30,7 +30,7 @@ RCSID("$OpenBSD: msg.c,v 1.6 2003/06/28 16:23:06 deraadt Exp $"); #include "atomicio.h" #include "msg.h" -void +int ssh_msg_send(int fd, u_char type, Buffer *m) { u_char buf[5]; @@ -40,10 +40,15 @@ ssh_msg_send(int fd, u_char type, Buffer *m) PUT_32BIT(buf, mlen + 1); buf[4] = type; /* 1st byte of payload is mesg-type */ - if (atomicio(vwrite, fd, buf, sizeof(buf)) != sizeof(buf)) - fatal("ssh_msg_send: write"); - if (atomicio(vwrite, fd, buffer_ptr(m), mlen) != mlen) - fatal("ssh_msg_send: write"); + if (atomicio(vwrite, fd, buf, sizeof(buf)) != sizeof(buf)) { + error("ssh_msg_send: write"); + return (-1); + } + if (atomicio(vwrite, fd, buffer_ptr(m), mlen) != mlen) { + error("ssh_msg_send: write"); + return (-1); + } + return (0); } int @@ -57,17 +62,21 @@ ssh_msg_recv(int fd, Buffer *m) res = atomicio(read, fd, buf, sizeof(buf)); if (res != sizeof(buf)) { - if (res == 0) - return -1; - fatal("ssh_msg_recv: read: header %ld", (long)res); + if (res != 0) + error("ssh_msg_recv: read: header %ld", (long)res); + return (-1); } msg_len = GET_32BIT(buf); - if (msg_len > 256 * 1024) - fatal("ssh_msg_recv: read: bad msg_len %u", msg_len); + if (msg_len > 256 * 1024) { + error("ssh_msg_recv: read: bad msg_len %u", msg_len); + return (-1); + } buffer_clear(m); buffer_append_space(m, msg_len); res = atomicio(read, fd, buffer_ptr(m), msg_len); - if (res != msg_len) - fatal("ssh_msg_recv: read: %ld != msg_len", (long)res); - return 0; + if (res != msg_len) { + error("ssh_msg_recv: read: %ld != msg_len", (long)res); + return (-1); + } + return (0); } |