diff options
Diffstat (limited to 'Swiften/FileTransfer')
3 files changed, 15 insertions, 14 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp index fadfd46..477af4b 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp @@ -10,6 +10,7 @@ #include <iostream> #include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/SafeByteArray.h> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/Concat.h> #include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h> @@ -36,7 +37,7 @@ void SOCKS5BytestreamServerSession::stop() { finish(false); } -void SOCKS5BytestreamServerSession::handleDataRead(const ByteArray& data) { +void SOCKS5BytestreamServerSession::handleDataRead(const SafeByteArray& data) { append(unprocessedData, data); process(); } @@ -56,7 +57,7 @@ void SOCKS5BytestreamServerSession::process() { std::cerr << "SOCKS5BytestreamServerSession: Junk after authentication mechanism"; } unprocessedData.clear(); - connection->write(createByteArray("\x05\x00", 2)); + connection->write(createSafeByteArray("\x05\x00", 2)); state = WaitingForRequest; } } @@ -77,7 +78,7 @@ void SOCKS5BytestreamServerSession::process() { std::cerr << "SOCKS5BytestreamServerSession: Junk after authentication mechanism"; } bytestream = bytestreams->getBytestream(byteArrayToString(requestID)); - ByteArray result = createByteArray("\x05", 1); + SafeByteArray result = createSafeByteArray("\x05", 1); result.push_back(bytestream ? 0x0 : 0x4); append(result, createByteArray("\x00\x03", 2)); result.push_back(static_cast<char>(requestID.size())); @@ -99,7 +100,7 @@ void SOCKS5BytestreamServerSession::process() { void SOCKS5BytestreamServerSession::sendData() { if (!bytestream->isFinished()) { try { - connection->write(bytestream->read(chunkSize)); + connection->write(createSafeByteArray(bytestream->read(chunkSize))); } catch (const BytestreamException&) { finish(true); diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h index 80965fb..761a365 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h +++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.h @@ -40,7 +40,7 @@ namespace Swift { private: void finish(bool error); void process(); - void handleDataRead(const ByteArray&); + void handleDataRead(const SafeByteArray&); void sendData(); private: diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp index d4c31c5..06bc98f 100644 --- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamServerSessionTest.cpp @@ -48,7 +48,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession()); StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); - receive(createByteArray("\x05\x02\x01\x02")); + receive(createSafeByteArray("\x05\x02\x01\x02")); CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData); } @@ -57,10 +57,10 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { boost::shared_ptr<SOCKS5BytestreamServerSession> testling(createSession()); StartStopper<SOCKS5BytestreamServerSession> stopper(testling.get()); - receive(createByteArray("\x05\x02\x01")); + receive(createSafeByteArray("\x05\x02\x01")); CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedData.size())); - receive(createByteArray("\x01")); + receive(createSafeByteArray("\x01")); CPPUNIT_ASSERT(createByteArray("\x05\x00", 2) == receivedData); } @@ -71,7 +71,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { authenticate(); ByteArray hostname(createByteArray("abcdef")); - receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), hostname, createByteArray("\x00\x00", 2))); + receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2))); CPPUNIT_ASSERT(createByteArray("\x05\x00\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == createByteArray(&receivedData[0], 13)); } @@ -81,7 +81,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { authenticate(); ByteArray hostname(createByteArray("abcdef")); - receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), hostname, createByteArray("\x00\x00", 2))); + receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2))); CPPUNIT_ASSERT(createByteArray("\x05\x04\x00\x03\x06\x61\x62\x63\x64\x65\x66\x00\x00", 13) == receivedData); } @@ -113,19 +113,19 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { } private: - void receive(const ByteArray& data) { + void receive(const SafeByteArray& data) { connection->receive(data); eventLoop->processEvents(); } void authenticate() { - receive(createByteArray("\x05\x02\x01\x02")); + receive(createSafeByteArray("\x05\x02\x01\x02")); receivedData.clear(); receivedDataChunks = 0; } void request(const std::string& hostname) { - receive(concat(createByteArray("\x05\x01\x00\x03", 4), createByteArray(hostname.size()), createByteArray(hostname), createByteArray("\x00\x00", 2))); + receive(concat(createSafeByteArray("\x05\x01\x00\x03", 4), createSafeByteArray(hostname.size()), createSafeByteArray(hostname), createSafeByteArray("\x00\x00", 2))); } void skipHeader(const std::string& hostname) { @@ -134,7 +134,7 @@ class SOCKS5BytestreamServerSessionTest : public CppUnit::TestFixture { } - void handleDataWritten(const ByteArray& data) { + void handleDataWritten(const SafeByteArray& data) { receivedData.insert(receivedData.end(), data.begin(), data.end()); receivedDataChunks++; } |