Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable STDIN listening when not needed #1906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/browser/NativeMessagingBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@
#include <io.h>
#endif

NativeMessagingBase::NativeMessagingBase()
NativeMessagingBase::NativeMessagingBase(const bool enabled)
{
#ifdef Q_OS_WIN
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#else
m_notifier.reset(new QSocketNotifier(fileno(stdin), QSocketNotifier::Read, this));
connect(m_notifier.data(), SIGNAL(activated(int)), this, SLOT(newNativeMessage()));
if (enabled) {
m_notifier.reset(new QSocketNotifier(fileno(stdin), QSocketNotifier::Read, this));
connect(m_notifier.data(), SIGNAL(activated(int)), this, SLOT(newNativeMessage()));
}
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/NativeMessagingBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NativeMessagingBase : public QObject
Q_OBJECT

public:
explicit NativeMessagingBase();
explicit NativeMessagingBase(const bool enabled);
~NativeMessagingBase() = default;

protected slots:
Expand Down
9 changes: 7 additions & 2 deletions src/browser/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <Winsock2.h>
#endif

NativeMessagingHost::NativeMessagingHost(DatabaseTabWidget* parent) :
NativeMessagingBase(),
NativeMessagingHost::NativeMessagingHost(DatabaseTabWidget* parent, const bool enabled) :
NativeMessagingBase(enabled),
m_mutex(QMutex::Recursive),
m_browserClients(m_browserService),
m_browserService(parent)
Expand Down Expand Up @@ -77,6 +77,11 @@ void NativeMessagingHost::run()
QString serverPath = getLocalServerPath();
QFile::remove(serverPath);

// Ensure that STDIN is not being listened when proxy is used
if (m_notifier->isEnabled()) {
m_notifier->setEnabled(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be handled by the base class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a precaution. It handles a situation where proxy has been disabled but is enabled again.

}

if (m_localServer->isListening()) {
m_localServer->close();
}
Expand Down
2 changes: 1 addition & 1 deletion src/browser/NativeMessagingHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NativeMessagingHost : public NativeMessagingBase
typedef QList<QLocalSocket*> SocketList;

public:
explicit NativeMessagingHost(DatabaseTabWidget* parent = 0);
explicit NativeMessagingHost(DatabaseTabWidget* parent = 0, const bool enabled = false);
~NativeMessagingHost();
int init();
void run();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class BrowserPlugin: public ISettingsPage
{
public:
BrowserPlugin(DatabaseTabWidget* tabWidget) {
m_nativeMessagingHost = QSharedPointer<NativeMessagingHost>(new NativeMessagingHost(tabWidget));
m_nativeMessagingHost = QSharedPointer<NativeMessagingHost>(new NativeMessagingHost(tabWidget, BrowserSettings::isEnabled()));
}

~BrowserPlugin() {
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <Winsock2.h>
#endif

NativeMessagingHost::NativeMessagingHost() : NativeMessagingBase()
NativeMessagingHost::NativeMessagingHost() : NativeMessagingBase(true)
{
m_localSocket = new QLocalSocket();
m_localSocket->connectToServer(getLocalServerPath());
Expand Down