From 99e9c641b20489f3dfebbba185cbbc205fe47f4d Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Sun, 16 Jan 2011 11:50:06 +0000 Subject: Use atomicio when flushing protocol 1 std{out,err} buffers at session close. This was a latent bug exposed by setting a SIGCHLD handler and spotted by kevin.brott AT gmail.com; ok dtucker@ --- usr.bin/ssh/clientloop.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'usr.bin/ssh') diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c index 891eb370e64..bf0dbda4fda 100644 --- a/usr.bin/ssh/clientloop.c +++ b/usr.bin/ssh/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.229 2011/01/11 06:13:10 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.230 2011/01/16 11:50:05 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1579,9 +1579,9 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id) /* Output any buffered data for stdout. */ while (buffer_len(&stdout_buffer) > 0) { - len = write(fileno(stdout), buffer_ptr(&stdout_buffer), - buffer_len(&stdout_buffer)); - if (len <= 0) { + len = atomicio(vwrite, fileno(stdout), + buffer_ptr(&stdout_buffer), buffer_len(&stdout_buffer)); + if (len != buffer_len(&stdout_buffer)) { error("Write failed flushing stdout buffer."); break; } @@ -1590,9 +1590,9 @@ client_loop(int have_pty, int escape_char_arg, int ssh2_chan_id) /* Output any buffered data for stderr. */ while (buffer_len(&stderr_buffer) > 0) { - len = write(fileno(stderr), buffer_ptr(&stderr_buffer), - buffer_len(&stderr_buffer)); - if (len <= 0) { + len = atomicio(vwrite, fileno(stderr), + buffer_ptr(&stderr_buffer), buffer_len(&stderr_buffer)); + if (len != buffer_len(&stderr_buffer)) { error("Write failed flushing stderr buffer."); break; } -- cgit v1.2.3