From 7e37c6eb7e54e99b74c340eede2b7713b352160e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Sun, 13 Dec 2015 22:35:01 +0100 Subject: [PATCH 1/5] Disable exception throwing if receive 0 bytes. #6 --- src/Transport.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Transport.cpp b/src/Transport.cpp index a65bf28..ae25046 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -314,7 +314,8 @@ void mumlib::Transport::doReceiveSsl() { } else { logger.error("SSL receiver error: %s. Bytes transferred: %d.", ec.message().c_str(), bytesTransferred); - throwTransportException("receive failed: " + ec.message()); + //todo temporarily disable exception throwing until issue #6 is solved + //throwTransportException("receive failed: " + ec.message()); } }); } From 4b8fad826327a79af7856f5d06efbb6546652cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Mon, 14 Dec 2015 01:44:02 +0100 Subject: [PATCH 2/5] Add exception when input SSL buffer is overflown. #6 --- src/Transport.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Transport.cpp b/src/Transport.cpp index ae25046..9838eeb 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -292,9 +292,16 @@ void mumlib::Transport::doReceiveSsl() { } const int payloadSize = ntohl(*reinterpret_cast(sslIncomingBuffer + 2)); - size_t remaining = payloadSize + 6 - bytesTransferred; + const int wholeMessageLength = payloadSize + 6; + size_t remaining = wholeMessageLength - bytesTransferred; remaining = max(remaining, (size_t) 0); + if (wholeMessageLength > MAX_TCP_LENGTH) { + throwTransportException( + (boost::format("message bigger (%d B) than max allowed size (%d B)") + % wholeMessageLength % MAX_TCP_LENGTH).str()); + } + return remaining; }, [this](const boost::system::error_code &ec, size_t bytesTransferred) { From 7a45a4c40dfe9074f572254ada8d34f4c59b4c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Mon, 14 Dec 2015 02:36:25 +0100 Subject: [PATCH 3/5] Fix wrong channel texting after channel join. --- include/mumlib.hpp | 2 +- include/mumlib/Callback.hpp | 2 +- src/mumlib.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/mumlib.hpp b/include/mumlib.hpp index 992321c..5df4f50 100644 --- a/include/mumlib.hpp +++ b/include/mumlib.hpp @@ -41,7 +41,7 @@ namespace mumlib { void sendTextMessage(std::string message); - void joinChannel(int channel_id); + void joinChannel(int channelId); private: _Mumlib_Private *impl; diff --git a/include/mumlib/Callback.hpp b/include/mumlib/Callback.hpp index 7ff4aa6..a11b7b4 100644 --- a/include/mumlib/Callback.hpp +++ b/include/mumlib/Callback.hpp @@ -179,7 +179,7 @@ namespace mumlib { string welcome_text, int32_t session, int32_t max_bandwidth, - int64_t permissions); + int64_t permissions) override; virtual void channelRemove(uint32_t channel_id) override; diff --git a/src/mumlib.cpp b/src/mumlib.cpp index 3465d6d..10609cb 100644 --- a/src/mumlib.cpp +++ b/src/mumlib.cpp @@ -379,9 +379,10 @@ namespace mumlib { impl->transport.sendControlMessage(MessageType::TEXTMESSAGE, textMessage); } - void Mumlib::joinChannel(int channel_id) { + void Mumlib::joinChannel(int channelId) { MumbleProto::UserState userState; - userState.set_channel_id(channel_id); + userState.set_channel_id(channelId); impl->transport.sendControlMessage(MessageType::USERSTATE, userState); + impl->channelId = channelId; } } From 2617016706eea8b0b7ce7417702617b3dcad0145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Mon, 14 Dec 2015 22:44:32 +0100 Subject: [PATCH 4/5] Fix crash after channel linking. --- src/mumlib.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/mumlib.cpp b/src/mumlib.cpp index 10609cb..a5dbb3a 100644 --- a/src/mumlib.cpp +++ b/src/mumlib.cpp @@ -87,6 +87,8 @@ namespace mumlib { private: bool processIncomingTcpMessage(MessageType messageType, uint8_t *buffer, int length) { + logger.debug("Process incoming message: type %d, length: %d.", messageType, length); + switch (messageType) { case MessageType::VERSION: { MumbleProto::Version version; @@ -133,14 +135,19 @@ namespace mumlib { int position = channelState.has_position() ? channelState.position() : 0; vector links; - std::copy(channelState.links().begin(), channelState.links().end(), links.begin()); + for (int i = 0; i < channelState.links_size(); ++i) { + links.push_back(channelState.links(i)); + } vector links_add; - std::copy(channelState.links_add().begin(), channelState.links_add().end(), links_add.begin()); + for (int i = 0; i < channelState.links_add_size(); ++i) { + links_add.push_back(channelState.links_add(i)); + } vector links_remove; - std::copy(channelState.links_remove().begin(), channelState.links_remove().end(), - links_remove.begin()); + for (int i = 0; i < channelState.links_remove_size(); ++i) { + links_remove.push_back(channelState.links_remove(i)); + } this->channelId = channel_id; From 44f2bbd5c3300912d9fa948c54c13eac10486cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Wed, 20 Jan 2016 21:46:49 +0100 Subject: [PATCH 5/5] Increase SSL input buffer to handle images. #7 --- include/mumlib/Transport.hpp | 5 ++--- src/Transport.cpp | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/mumlib/Transport.hpp b/include/mumlib/Transport.hpp index 433106f..ccf94a7 100644 --- a/include/mumlib/Transport.hpp +++ b/include/mumlib/Transport.hpp @@ -18,7 +18,7 @@ namespace mumlib { constexpr int MAX_UDP_LENGTH = 1024; - constexpr int MAX_TCP_LENGTH = 2048; + constexpr int MAX_TCP_LENGTH = 129 * 1024; // 128 kB + some reserve using namespace std; using namespace boost::asio; @@ -85,8 +85,7 @@ namespace mumlib { ssl::context sslContext; ssl::stream sslSocket; - uint8_t sslIncomingBuffer[MAX_TCP_LENGTH]; - + uint8_t *sslIncomingBuffer; deadline_timer pingTimer; std::chrono::time_point lastReceivedUdpPacketTimestamp; diff --git a/src/Transport.cpp b/src/Transport.cpp index 9838eeb..f134512 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -42,11 +42,14 @@ mumlib::Transport::Transport( pingTimer(ioService, PING_INTERVAL), asyncBufferPool(max(MAX_UDP_LENGTH, MAX_TCP_LENGTH)) { + sslIncomingBuffer = new uint8_t[MAX_TCP_LENGTH]; + pingTimer.async_wait(boost::bind(&Transport::pingTimerTick, this, _1)); } mumlib::Transport::~Transport() { disconnect(); + delete[] sslIncomingBuffer; } void mumlib::Transport::connect(