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

#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
ssh_channel channel = nullptr;
explicit ChannelImpl(ssh_session session)
{
radix_tagged_line("ChannelImpl::ChannelImpl()");
channel = ssh_channel_new(session);
}
~ChannelImpl()
{
radix_tagged_line("ChannelImpl::~ChannelImpl()");
if (channel != nullptr)
{
ssh_channel_close(channel);
......@@ -101,8 +103,8 @@ QString Channel::readExecOut()
int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 0);
if (nbytes > 0)
{
buffer[nbytes] = '\0';
QString result = buffer;
buffer[nbytes - 1] = '\0';
QString result = buffer;
return result;
}
return QString("");
......@@ -114,8 +116,8 @@ QString Channel::readExecErr()
int nbytes = ssh_channel_read(p->channel, buffer, sizeof(buffer), 1);
if (nbytes > 0)
{
buffer[nbytes] = '\0';
QString result = buffer;
buffer[nbytes - 1] = '\0';
QString result = buffer;
return result;
}
return QString("");
......@@ -698,11 +700,11 @@ SessionAuthState Session::authenticatePrompts(QStringList responses)
return state;
}
Channel Session::newChannel()
Channel* Session::newChannel()
{
assert_ssh_session(p->session, "newChannel() -- Session is not allocated.");
Channel channel;
channel.p = new ChannelImpl(p->session);
Channel* channel = new Channel;
channel->p = new ChannelImpl(p->session);
return channel;
}
......
......@@ -301,7 +301,7 @@ class RSM_PUBLIC Session
* @brief newChannel Allocates a new execution channel from this session
* @return
*/
Channel newChannel();
Channel* newChannel();
/**
* @brief newSFTPSession Allocates a new SFTP session from this SSH session
......
......@@ -250,10 +250,10 @@ void SessionWorker::authenticatePrompts(QStringList responses)
void SessionWorker::requestExec(QString command)
{
radix_tagged_line("requestExec(" << command.toStdString() << ")");
Channel channel = p->session->newChannel();
Channel* channel = p->session->newChannel();
// clear any previous buffer
p->output_buffer.clear();
bool rc = channel.open();
bool rc = channel->open();
if (!rc)
{
radix_tagged_line("Failed to open channel");
......@@ -261,35 +261,36 @@ void SessionWorker::requestExec(QString command)
return;
}
rc = channel.exec(command);
rc = channel->exec(command);
if (!rc)
{
radix_tagged_line("Failed to request exec.");
emit execFailed("Failed to execute remote command.");
channel.close();
channel->close();
return;
}
// TODO: should we use timeout or non-blocking version of this call?
// read stdout
QString bytes = channel.readExecOut();
QString bytes = channel->readExecOut();
while (!bytes.isEmpty())
{
p->output_buffer.append(bytes);
bytes = channel.readExecOut();
bytes = channel->readExecOut();
}
// read stderr
bytes = channel.readExecErr();
bytes = channel->readExecErr();
while (!bytes.isEmpty())
{
p->output_buffer.append(bytes);
bytes = channel.readExecErr();
bytes = channel->readExecErr();
}
emit execOutputReady();
radix_tagged_line("nbytes=" << p->output_buffer.size());
radix_tagged_line("Finished reading response\n" << p->output_buffer.data());
channel.close();
channel->close();
delete channel;
radix_tagged_line("'" << command.toStdString() << "' finished.");
emit execFinished();
}
......
......@@ -8,7 +8,7 @@
#endif
using namespace rsm;
TEST(RSM, SessionController)
TEST(RSM, DISABLED_SessionController)
{
SessionController controller;
controller.setHost("apollo");
......
......@@ -4,7 +4,7 @@
#include "rsmcore/sessionworker.hh"
using namespace rsm;
TEST(RSM, SessionWorker)
TEST(RSM, DISABLED_SessionWorker)
{
SessionWorker session("apollo");
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