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

Socket buffer fix #1720

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
5 changes: 3 additions & 2 deletions src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QJsonParseError>
#include "BrowserAction.h"
#include "BrowserSettings.h"
#include "NativeMessagingBase.h"
#include "sodium.h"
#include "sodium/crypto_box.h"
#include "sodium/randombytes.h"
Expand Down Expand Up @@ -456,7 +457,7 @@ QString BrowserAction::encrypt(const QString plaintext, const QString nonce)
std::vector<unsigned char> sk(sa.cbegin(), sa.cend());

std::vector<unsigned char> e;
e.resize(max_length);
e.resize(NATIVE_MSG_MAX_LENGTH);

if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
return QString();
Expand Down Expand Up @@ -484,7 +485,7 @@ QByteArray BrowserAction::decrypt(const QString encrypted, const QString nonce)
std::vector<unsigned char> sk(sa.cbegin(), sa.cend());

std::vector<unsigned char> d;
d.resize(max_length);
d.resize(NATIVE_MSG_MAX_LENGTH);

if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
return QByteArray();
Expand Down
2 changes: 0 additions & 2 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include "gui/DatabaseTabWidget.h"
#include "core/Entry.h"

enum { max_length = 16*1024 };

class BrowserService : public QObject
{
Q_OBJECT
Expand Down
7 changes: 7 additions & 0 deletions src/browser/NativeMessagingBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#include <iostream>
#include <unistd.h>

#ifndef Q_OS_WIN
#include <sys/types.h>
#include <sys/socket.h>
#endif

static const int NATIVE_MSG_MAX_LENGTH = 1024*1024;

class NativeMessagingBase : public QObject
{
Q_OBJECT
Expand Down
8 changes: 7 additions & 1 deletion src/browser/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,17 @@ void NativeMessagingHost::newLocalConnection()
void NativeMessagingHost::newLocalMessage()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(QObject::sender());

if (!socket || socket->bytesAvailable() <= 0) {
return;
}

socket->setReadBufferSize(NATIVE_MSG_MAX_LENGTH);
int socketDesc = socket->socketDescriptor();
if (socketDesc) {
int max = NATIVE_MSG_MAX_LENGTH;
setsockopt(socketDesc, SOL_SOCKET, SO_SNDBUF, &max, sizeof(max));
}

QByteArray arr = socket->readAll();
if (arr.isEmpty()) {
return;
Expand Down
7 changes: 7 additions & 0 deletions src/proxy/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ NativeMessagingHost::NativeMessagingHost() : NativeMessagingBase()
{
m_localSocket = new QLocalSocket();
m_localSocket->connectToServer(getLocalServerPath());
m_localSocket->setReadBufferSize(NATIVE_MSG_MAX_LENGTH);

int socketDesc = m_localSocket->socketDescriptor();
if (socketDesc) {
int max = NATIVE_MSG_MAX_LENGTH;
setsockopt(socketDesc, SOL_SOCKET, SO_SNDBUF, &max, sizeof(max));
}
#ifdef Q_OS_WIN
m_running.store(true);
m_future = QtConcurrent::run(this, static_cast<void(NativeMessagingHost::*)()>(&NativeMessagingHost::readNativeMessages));
Expand Down