Commit efc89193 authored by Norby, Tom's avatar Norby, Tom
Browse files

#2. Disable incomplete tests; change newChannel to return pointer; protect against out of bounds.

parent 546cf4d7
Pipeline #100736 passed with stages
in 5 minutes and 44 seconds
...@@ -39,10 +39,12 @@ class ChannelImpl ...@@ -39,10 +39,12 @@ class ChannelImpl
ssh_channel channel = nullptr; ssh_channel channel = nullptr;
explicit ChannelImpl(ssh_session session) explicit ChannelImpl(ssh_session session)
{ {
radix_tagged_line("ChannelImpl::ChannelImpl()");
channel = ssh_channel_new(session); channel = ssh_channel_new(session);
} }
~ChannelImpl() ~ChannelImpl()
{ {
radix_tagged_line("ChannelImpl::~ChannelImpl()");
if (channel != nullptr) if (channel != nullptr)
{ {
ssh_channel_close(channel); ssh_channel_close(channel);
...@@ -101,7 +103,7 @@ QString Channel::readExecOut() ...@@ -101,7 +103,7 @@ QString Channel::readExecOut()
int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 0); int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 0);
if (nbytes > 0) if (nbytes > 0)
{ {
buffer[nbytes] = '\0'; buffer[nbytes - 1] = '\0';
QString result = buffer; QString result = buffer;
return result; return result;
} }
...@@ -114,7 +116,7 @@ QString Channel::readExecErr() ...@@ -114,7 +116,7 @@ QString Channel::readExecErr()
int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 1); int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 1);
if (nbytes > 0) if (nbytes > 0)
{ {
buffer[nbytes] = '\0'; buffer[nbytes - 1] = '\0';
QString result = buffer; QString result = buffer;
return result; return result;
} }
...@@ -698,11 +700,11 @@ SessionAuthState Session::authenticatePrompts(QStringList responses) ...@@ -698,11 +700,11 @@ SessionAuthState Session::authenticatePrompts(QStringList responses)
return state; return state;
} }
Channel Session::newChannel() Channel* Session::newChannel()
{ {
assert_ssh_session(p->session, "newChannel() -- Session is not allocated."); assert_ssh_session(p->session, "newChannel() -- Session is not allocated.");
Channel channel; Channel* channel = new Channel;
channel.p = new ChannelImpl(p->session); channel->p = new ChannelImpl(p->session);
return channel; return channel;
} }
......
...@@ -301,7 +301,7 @@ class RSM_PUBLIC Session ...@@ -301,7 +301,7 @@ class RSM_PUBLIC Session
* @brief newChannel Allocates a new execution channel from this session * @brief newChannel Allocates a new execution channel from this session
* @return * @return
*/ */
Channel newChannel(); Channel* newChannel();
/** /**
* @brief newSFTPSession Allocates a new SFTP session from this SSH session * @brief newSFTPSession Allocates a new SFTP session from this SSH session
......
...@@ -250,10 +250,10 @@ void SessionWorker::authenticatePrompts(QStringList responses) ...@@ -250,10 +250,10 @@ void SessionWorker::authenticatePrompts(QStringList responses)
void SessionWorker::requestExec(QString command) void SessionWorker::requestExec(QString command)
{ {
radix_tagged_line("requestExec(" << command.toStdString() << ")"); radix_tagged_line("requestExec(" << command.toStdString() << ")");
Channel channel = p->session->newChannel(); Channel* channel = p->session->newChannel();
// clear any previous buffer // clear any previous buffer
p->output_buffer.clear(); p->output_buffer.clear();
bool rc = channel.open(); bool rc = channel->open();
if (!rc) if (!rc)
{ {
radix_tagged_line("Failed to open channel"); radix_tagged_line("Failed to open channel");
...@@ -261,35 +261,36 @@ void SessionWorker::requestExec(QString command) ...@@ -261,35 +261,36 @@ void SessionWorker::requestExec(QString command)
return; return;
} }
rc = channel.exec(command); rc = channel->exec(command);
if (!rc) if (!rc)
{ {
radix_tagged_line("Failed to request exec."); radix_tagged_line("Failed to request exec.");
emit execFailed("Failed to execute remote command."); emit execFailed("Failed to execute remote command.");
channel.close(); channel->close();
return; return;
} }
// TODO: should we use timeout or non-blocking version of this call? // TODO: should we use timeout or non-blocking version of this call?
// read stdout // read stdout
QString bytes = channel.readExecOut(); QString bytes = channel->readExecOut();
while (!bytes.isEmpty()) while (!bytes.isEmpty())
{ {
p->output_buffer.append(bytes); p->output_buffer.append(bytes);
bytes = channel.readExecOut(); bytes = channel->readExecOut();
} }
// read stderr // read stderr
bytes = channel.readExecErr(); bytes = channel->readExecErr();
while (!bytes.isEmpty()) while (!bytes.isEmpty())
{ {
p->output_buffer.append(bytes); p->output_buffer.append(bytes);
bytes = channel.readExecErr(); bytes = channel->readExecErr();
} }
emit execOutputReady(); emit execOutputReady();
radix_tagged_line("nbytes=" << p->output_buffer.size()); radix_tagged_line("nbytes=" << p->output_buffer.size());
radix_tagged_line("Finished reading response\n" << p->output_buffer.data()); radix_tagged_line("Finished reading response\n" << p->output_buffer.data());
channel.close(); channel->close();
delete channel;
radix_tagged_line("'" << command.toStdString() << "' finished."); radix_tagged_line("'" << command.toStdString() << "' finished.");
emit execFinished(); emit execFinished();
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#endif #endif
using namespace rsm; using namespace rsm;
TEST(RSM, SessionController) TEST(RSM, DISABLED_SessionController)
{ {
SessionController controller; SessionController controller;
controller.setHost("apollo"); controller.setHost("apollo");
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "rsmcore/sessionworker.hh" #include "rsmcore/sessionworker.hh"
using namespace rsm; using namespace rsm;
TEST(RSM, SessionWorker) TEST(RSM, DISABLED_SessionWorker)
{ {
SessionWorker session("apollo"); SessionWorker session("apollo");
session.setLogVerbosity(SessionVerbosity::None); session.setLogVerbosity(SessionVerbosity::None);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment