diff options
Diffstat (limited to 'Swiften/FileTransfer')
| -rw-r--r-- | Swiften/FileTransfer/ByteArrayReadBytestream.cpp | 22 | ||||
| -rw-r--r-- | Swiften/FileTransfer/IBBSendSession.cpp | 4 | ||||
| -rw-r--r-- | Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp | 11 | ||||
| -rw-r--r-- | Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp | 4 |
4 files changed, 27 insertions, 14 deletions
diff --git a/Swiften/FileTransfer/ByteArrayReadBytestream.cpp b/Swiften/FileTransfer/ByteArrayReadBytestream.cpp index cd9fa4a..3fdff27 100644 --- a/Swiften/FileTransfer/ByteArrayReadBytestream.cpp +++ b/Swiften/FileTransfer/ByteArrayReadBytestream.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -19,13 +19,19 @@ std::shared_ptr<ByteArray> ByteArrayReadBytestream::read(size_t size) { | |||
| 19 | if (position + readSize > data.size()) { | 19 | if (position + readSize > data.size()) { |
| 20 | readSize = data.size() - position; | 20 | readSize = data.size() - position; |
| 21 | } | 21 | } |
| 22 | std::shared_ptr<ByteArray> result = std::make_shared<ByteArray>( | 22 | try { |
| 23 | data.begin() + boost::numeric_cast<long long>(position), | 23 | std::shared_ptr<ByteArray> result = std::make_shared<ByteArray>( |
| 24 | data.begin() + boost::numeric_cast<long long>(position) + boost::numeric_cast<long long>(readSize)); | 24 | data.begin() + boost::numeric_cast<long long>(position), |
| 25 | 25 | data.begin() + boost::numeric_cast<long long>(position) + boost::numeric_cast<long long>(readSize)); | |
| 26 | onRead(*result); | 26 | onRead(*result); |
| 27 | position += readSize; | 27 | position += readSize; |
| 28 | return result; | 28 | return result; |
| 29 | } | ||
| 30 | catch (const boost::numeric::bad_numeric_cast&) { | ||
| 31 | // If we cannot cast to long long, we probably ran out of memory long ago | ||
| 32 | assert(false); | ||
| 33 | return {}; | ||
| 34 | } | ||
| 29 | } | 35 | } |
| 30 | 36 | ||
| 31 | void ByteArrayReadBytestream::addData(const std::vector<unsigned char>& moreData) { | 37 | void ByteArrayReadBytestream::addData(const std::vector<unsigned char>& moreData) { |
diff --git a/Swiften/FileTransfer/IBBSendSession.cpp b/Swiften/FileTransfer/IBBSendSession.cpp index e51c91c..258412b 100644 --- a/Swiften/FileTransfer/IBBSendSession.cpp +++ b/Swiften/FileTransfer/IBBSendSession.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -40,7 +40,7 @@ IBBSendSession::~IBBSendSession() { | |||
| 40 | 40 | ||
| 41 | void IBBSendSession::start() { | 41 | void IBBSendSession::start() { |
| 42 | IBBRequest::ref request = IBBRequest::create( | 42 | IBBRequest::ref request = IBBRequest::create( |
| 43 | from, to, IBB::createIBBOpen(id, boost::numeric_cast<int>(blockSize)), router); | 43 | from, to, IBB::createIBBOpen(id, blockSize), router); |
| 44 | request->onResponse.connect(boost::bind(&IBBSendSession::handleIBBResponse, this, _1, _2)); | 44 | request->onResponse.connect(boost::bind(&IBBSendSession::handleIBBResponse, this, _1, _2)); |
| 45 | active = true; | 45 | active = true; |
| 46 | request->send(); | 46 | request->send(); |
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp index bc4e8e4..0fd40bf 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamServerSession.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -138,7 +138,14 @@ void SOCKS5BytestreamServerSession::process() { | |||
| 138 | SafeByteArray result = createSafeByteArray("\x05", 1); | 138 | SafeByteArray result = createSafeByteArray("\x05", 1); |
| 139 | result.push_back(hasBytestream ? 0x0 : 0x4); | 139 | result.push_back(hasBytestream ? 0x0 : 0x4); |
| 140 | append(result, createByteArray("\x00\x03", 2)); | 140 | append(result, createByteArray("\x00\x03", 2)); |
| 141 | result.push_back(boost::numeric_cast<unsigned char>(requestID.size())); | 141 | try { |
| 142 | result.push_back(boost::numeric_cast<unsigned char>(requestID.size())); | ||
| 143 | } | ||
| 144 | catch (const boost::numeric::bad_numeric_cast& e) { | ||
| 145 | SWIFT_LOG(warning) << "SOCKS5 request ID is too long (" << requestID.size() << "): " << e.what() << std::endl; | ||
| 146 | finish(); | ||
| 147 | return; | ||
| 148 | } | ||
| 142 | append(result, concat(requestID, createByteArray("\x00\x00", 2))); | 149 | append(result, concat(requestID, createByteArray("\x00\x00", 2))); |
| 143 | if (!hasBytestream) { | 150 | if (!hasBytestream) { |
| 144 | SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!" << std::endl; | 151 | SWIFT_LOG(debug) << "Readstream or Wrtiestream with ID " << streamID << " not found!" << std::endl; |
diff --git a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp index f9057f8..2399cbe 100644 --- a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp +++ b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2010-2016 Isode Limited. | 2 | * Copyright (c) 2010-2018 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| @@ -58,7 +58,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture { | |||
| 58 | CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(0, JID("foo@bar.com/baz"), IQ::Set)); | 58 | CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<IBB>(0, JID("foo@bar.com/baz"), IQ::Set)); |
| 59 | IBB::ref ibb = stanzaChannel->sentStanzas[0]->getPayload<IBB>(); | 59 | IBB::ref ibb = stanzaChannel->sentStanzas[0]->getPayload<IBB>(); |
| 60 | CPPUNIT_ASSERT_EQUAL(IBB::Open, ibb->getAction()); | 60 | CPPUNIT_ASSERT_EQUAL(IBB::Open, ibb->getAction()); |
| 61 | CPPUNIT_ASSERT_EQUAL(1234, ibb->getBlockSize()); | 61 | CPPUNIT_ASSERT_EQUAL(1234u, ibb->getBlockSize()); |
| 62 | CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID()); | 62 | CPPUNIT_ASSERT_EQUAL(std::string("myid"), ibb->getStreamID()); |
| 63 | } | 63 | } |
| 64 | 64 | ||
Swift