mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-24 19:37:48 +03:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user