diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-04-14 21:24:28 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-04-14 21:24:28 +0200 |
commit | 79d51099ac3273aa73c3bd3bd047b3fa996fef18 (patch) | |
tree | cc2d6f0f212b735b582f094c93801e4101c23303 /examples/sshnetcat.c | |
parent | adf23533e02d997118d1732f91abf9f116a47cec (diff) | |
download | libssh-79d51099ac3273aa73c3bd3bd047b3fa996fef18.tar.gz libssh-79d51099ac3273aa73c3bd3bd047b3fa996fef18.tar.xz libssh-79d51099ac3273aa73c3bd3bd047b3fa996fef18.zip |
examples: Fix a bad shift if ssh_get_fd() returns -1.
Found by Coverity.
CID: #1199454
Diffstat (limited to 'examples/sshnetcat.c')
-rw-r--r-- | examples/sshnetcat.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/sshnetcat.c b/examples/sshnetcat.c index 4ed408da..8ac5a212 100644 --- a/examples/sshnetcat.c +++ b/examples/sshnetcat.c @@ -87,13 +87,23 @@ static void select_loop(ssh_session session,ssh_channel channel){ int ret; while(channel){ do{ + int fd; + FD_ZERO(&fds); if(!eof) FD_SET(0,&fds); timeout.tv_sec=30; timeout.tv_usec=0; - FD_SET(ssh_get_fd(session),&fds); - maxfd=ssh_get_fd(session)+1; + + fd = ssh_get_fd(session); + if (fd == -1) { + fprintf(stderr, "Error getting the session file descriptor: %s\n", + ssh_get_error(session)); + return; + } + FD_SET(fd, &fds); + maxfd = fd + 1; + channels[0]=channel; // set the first channel we want to read from channels[1]=NULL; ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout); |