Skip to content
Snippets Groups Projects
Commit 661f6eb9 authored by Jan David Mol's avatar Jan David Mol
Browse files

Task #2669: Fixes ever-expanding input buffer for SSHconnection

parent fb0c0965
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <vector> #include <vector>
#include <string>
#include <sstream>
#ifdef HAVE_LIBSSH2 #ifdef HAVE_LIBSSH2
#include <Scheduling.h> #include <Scheduling.h>
...@@ -217,7 +219,6 @@ void SSHconnection::commThread() ...@@ -217,7 +219,6 @@ void SSHconnection::commThread()
LOG_DEBUG_STR( itsLogPrefix << "Connected" ); LOG_DEBUG_STR( itsLogPrefix << "Connected" );
stringstream buffer;
int rc; int rc;
int exitcode; int exitcode;
char *exitsignal=(char *)"none"; char *exitsignal=(char *)"none";
...@@ -247,16 +248,24 @@ void SSHconnection::commThread() ...@@ -247,16 +248,24 @@ void SSHconnection::commThread()
LOG_DEBUG_STR( itsLogPrefix << "Remote command started, waiting for output" ); LOG_DEBUG_STR( itsLogPrefix << "Remote command started, waiting for output" );
// raw input buffer
char data[0x1000];
// the current line (or line remnant)
string line("");
/* Session I/O */ /* Session I/O */
for( ;; ) for( ;; )
{ {
/* loop until we block */ /* loop until we block */
do { do {
char data[0x4000];
rc = libssh2_channel_read( channel, data, sizeof data ); rc = libssh2_channel_read( channel, data, sizeof data );
if( rc > 0 ) if( rc > 0 )
{ {
// create a buffer for line + data
stringstream buffer;
buffer << line;
buffer.write( data, rc ); buffer.write( data, rc );
/* extract and log lines */ /* extract and log lines */
...@@ -264,16 +273,15 @@ void SSHconnection::commThread() ...@@ -264,16 +273,15 @@ void SSHconnection::commThread()
{ {
Cancellation::point(); Cancellation::point();
buffer.getline( data, sizeof data ); std::getline( buffer, line );
if (buffer.fail()) { if (!buffer.good()) {
// no line found // 'line' now holds the remnant
buffer.clear();
break; break;
} }
// TODO: Use logger somehow (we'd duplicate the prefix if we just use LOG_* macros..) // TODO: Use logger somehow (we'd duplicate the prefix if we just use LOG_* macros..)
cout << data << endl; cout << line << endl;
} }
} else { } else {
if( rc < 0 && rc != LIBSSH2_ERROR_EAGAIN ) { if( rc < 0 && rc != LIBSSH2_ERROR_EAGAIN ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment