fix crash on port scan

This commit is contained in:
badaix 2017-10-09 18:35:19 +02:00
parent a490402721
commit b1edc34f6e
4 changed files with 47 additions and 30 deletions

View file

@ -8,13 +8,15 @@ snapclient (0.12.0) unstable; urgency=low
* Bugfixes * Bugfixes
-Snapclient: more reliable unique client id (Issue #249) -Snapclient: more reliable unique client id (Issue #249)
-Snapserver: fix config file permissions (Issue #251) -Snapserver: fix config file permissions (Issue #251)
-Fix linker error (Issue #255, #274) -Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238) -Snapserver: fix crash on "bye" from control client (Issue #238)
-Snapserver: fix crash on port scan (Issue #267)
* General * General
-Improved logging: Use "--debug" for debug logging -Improved logging: Use "--debug" for debug logging
-Log to file: Use "--debug=<filename>" -Log to file: Use "--debug=<filename>"
-Improved exception handling and error logging (Issue #276) -Improved exception handling and error logging (Issue #276)
-Android: update to NDK r16 and clang++ -Android: update to NDK r16 and clang++
-hide spotify credentials in json control message (Issue #282)
-- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200 -- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200

View file

@ -109,19 +109,26 @@ void ControlServer::startAccept()
void ControlServer::handleAccept(socket_ptr socket) void ControlServer::handleAccept(socket_ptr socket)
{ {
struct timeval tv; try
tv.tv_sec = 5;
tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
// socket->set_option(boost::asio::ip::tcp::no_delay(false));
SLOG(NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket);
{ {
std::lock_guard<std::recursive_mutex> mlock(mutex_); struct timeval tv;
session->start(); tv.tv_sec = 5;
sessions_.insert(session); tv.tv_usec = 0;
cleanup(); setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
// socket->set_option(boost::asio::ip::tcp::no_delay(false));
SLOG(NOTICE) << "ControlServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<ControlSession> session = make_shared<ControlSession>(this, socket);
{
std::lock_guard<std::recursive_mutex> mlock(mutex_);
session->start();
sessions_.insert(session);
cleanup();
}
}
catch (const std::exception& e)
{
SLOG(ERROR) << "Exception in ControlServer::handleAccept: " << e.what() << endl;
} }
startAccept(); startAccept();
} }

View file

@ -8,13 +8,15 @@ snapserver (0.12.0) unstable; urgency=low
* Bugfixes * Bugfixes
-Snapclient: more reliable unique client id (Issue #249) -Snapclient: more reliable unique client id (Issue #249)
-Snapserver: fix config file permissions (Issue #251) -Snapserver: fix config file permissions (Issue #251)
-Fix linker error (Issue #255, #274) -Fix linker error (Issue #255, #274)
-Snapserver: fix crash on "bye" from control client (Issue #238) -Snapserver: fix crash on "bye" from control client (Issue #238)
-Snapserver: fix crash on port scan (Issue #267)
* General * General
-Improved logging: Use "--debug" for debug logging -Improved logging: Use "--debug" for debug logging
-Log to file: Use "--debug=<filename>" -Log to file: Use "--debug=<filename>"
-Improved exception handling and error logging (Issue #276) -Improved exception handling and error logging (Issue #276)
-Android: update to NDK r16 and clang++ -Android: update to NDK r16 and clang++
-hide spotify credentials in json control message (Issue #282)
-- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200 -- Johannes Pohl <johannes.pohl@badaix.de> Tue, 04 Oct 2017 00:13:37 +0200

View file

@ -576,24 +576,30 @@ void StreamServer::startAccept()
void StreamServer::handleAccept(socket_ptr socket) void StreamServer::handleAccept(socket_ptr socket)
{ {
struct timeval tv; try
tv.tv_sec = 5; {
tv.tv_usec = 0; struct timeval tv;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); tv.tv_sec = 5;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); tv.tv_usec = 0;
setsockopt(socket->native_handle(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(socket->native_handle(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
/// experimental: turn on tcp::no_delay /// experimental: turn on tcp::no_delay
socket->set_option(tcp::no_delay(true)); socket->set_option(tcp::no_delay(true));
SLOG(NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl; SLOG(NOTICE) << "StreamServer::NewConnection: " << socket->remote_endpoint().address().to_string() << endl;
shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket); shared_ptr<StreamSession> session = make_shared<StreamSession>(this, socket);
session->setBufferMs(settings_.bufferMs); session->setBufferMs(settings_.bufferMs);
session->start(); session->start();
std::lock_guard<std::recursive_mutex> mlock(sessionsMutex_);
sessions_.insert(session);
std::lock_guard<std::recursive_mutex> mlock(sessionsMutex_);
sessions_.insert(session);
}
catch (const std::exception& e)
{
SLOG(ERROR) << "Exception in StreamServer::handleAccept: " << e.what() << endl;
}
startAccept(); startAccept();
} }