Fully initialize the argument to TIOCSWINSZ

struct winsize contains fields other than ws_col and ws_row.  To avoid passing
uninitialized data to TIOCSWINSZ, initialize it first using TIOCGWINSZ.

Found by Valgrind.

(closes #85 github issue)
This commit is contained in:
Keegan McAllister
2012-03-26 23:48:48 -04:00
committed by Keith Winstein
parent 9a7f3ad33d
commit ba9b16aafa
+4
View File
@@ -433,6 +433,10 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
/* tell child process of resize */ /* tell child process of resize */
const Parser::Resize *res = static_cast<const Parser::Resize *>( us.get_action( i ) ); const Parser::Resize *res = static_cast<const Parser::Resize *>( us.get_action( i ) );
struct winsize window_size; struct winsize window_size;
if ( ioctl( host_fd, TIOCGWINSZ, &window_size ) < 0 ) {
perror( "ioctl TIOCGWINSZ" );
return;
}
window_size.ws_col = res->width; window_size.ws_col = res->width;
window_size.ws_row = res->height; window_size.ws_row = res->height;
if ( ioctl( host_fd, TIOCSWINSZ, &window_size ) < 0 ) { if ( ioctl( host_fd, TIOCSWINSZ, &window_size ) < 0 ) {