aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Wiley <wiley@outlook.com>2021-05-01 12:14:54 -0700
committerAndrew Wiley <wiley@outlook.com>2021-06-04 22:27:51 -0700
commitbd7bef8b501f1a427ff10ad94164dfa4201bdc71 (patch)
tree2af749c672f5e0ec5ad899bb65aac653b3a4f302
parentfb8d120beca79466bf4f4eba1d6a2a268f4654c3 (diff)
downloadlibssh-bd7bef8b501f1a427ff10ad94164dfa4201bdc71.tar.gz
libssh-bd7bef8b501f1a427ff10ad94164dfa4201bdc71.tar.xz
libssh-bd7bef8b501f1a427ff10ad94164dfa4201bdc71.zip
fix error checks on channel writes in samplesshd-cb example
Signed-off-by: Andrew Wiley <wiley@outlook.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
-rw-r--r--examples/samplesshd-cb.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c
index 8bc70c47..c0758a2e 100644
--- a/examples/samplesshd-cb.c
+++ b/examples/samplesshd-cb.c
@@ -25,6 +25,10 @@ clients must be made or how a client should react.
#include <string.h>
#include <stdio.h>
+#ifdef _WIN32
+#include <io.h>
+#endif
+
#ifndef KEYS_FOLDER
#ifdef _WIN32
#define KEYS_FOLDER
@@ -241,7 +245,7 @@ int main(int argc, char **argv){
.channel_open_request_session_function = new_session_channel
};
- char buf[2048];
+ char buf[2049];
int i;
int r;
@@ -297,19 +301,24 @@ int main(int argc, char **argv){
} else
printf("Authenticated and got a channel\n");
do{
- i=ssh_channel_read(chan,buf, 2048, 0);
+ i=ssh_channel_read(chan, buf, sizeof(buf) - 1, 0);
if(i>0) {
- ssh_channel_write(chan, buf, i);
- if (write(1,buf,i) < 0) {
- printf("error writing to buffer\n");
+ if (ssh_channel_write(chan, buf, i) == SSH_ERROR) {
+ printf("error writing to channel\n");
return 1;
}
+
+ buf[i] = '\0';
+ printf("%s", buf);
+ fflush(stdout);
+
if (buf[0] == '\x0d') {
- if (write(1, "\n", 1) < 0) {
- printf("error writing to buffer\n");
+ if (ssh_channel_write(chan, "\n", 1) == SSH_ERROR) {
+ printf("error writing to channel\n");
return 1;
}
- ssh_channel_write(chan, "\n", 1);
+
+ printf("\n");
}
}
} while (i>0);