aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-06-17 12:35:42 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-06-17 12:35:42 +0200
commitd93e38bbfe7ab6d84ee064204d2d486342e564ae (patch)
tree2ff0c1bea347688a1642084993bdb5462d5c383b
parente4bcd063b7671a1cbe006fcbac9f4b304e03f3ec (diff)
downloadlibssh-d93e38bbfe7ab6d84ee064204d2d486342e564ae.tar.gz
libssh-d93e38bbfe7ab6d84ee064204d2d486342e564ae.tar.xz
libssh-d93e38bbfe7ab6d84ee064204d2d486342e564ae.zip
examples: Check return value of ssh_channel_read.
-rw-r--r--examples/scp_download.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/scp_download.c b/examples/scp_download.c
index bfd8dc4e..ba8782a7 100644
--- a/examples/scp_download.c
+++ b/examples/scp_download.c
@@ -58,6 +58,8 @@ static int opts(int argc, char **argv){
static void create_files(ssh_session session){
ssh_channel channel=ssh_channel_new(session);
char buffer[1];
+ int rc;
+
if(channel == NULL){
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
exit(EXIT_FAILURE);
@@ -74,8 +76,16 @@ static void create_files(ssh_session session){
exit(EXIT_FAILURE);
}
while(!ssh_channel_is_eof(channel)){
- ssh_channel_read(channel,buffer,1,1);
- if (write(1,buffer,1) < 0) {
+ rc = ssh_channel_read(channel,buffer,1,1);
+ if (rc != 1) {
+ fprintf(stderr, "Error reading from channel\n");
+ ssh_channel_close(channel);
+ ssh_channel_free(channel);
+ return;
+ }
+
+ rc = write(1, buffer, 1);
+ if (rc < 0) {
fprintf(stderr, "Error writing to buffer\n");
ssh_channel_close(channel);
ssh_channel_free(channel);