Socket buffer size fix (#1720)

This commit is contained in:
Sami Vänttinen 2018-04-03 05:13:07 +03:00 committed by Jonathan White
parent 0650b3084e
commit 3a92e4aab9
5 changed files with 24 additions and 5 deletions

View File

@ -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"
@ -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();
@ -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();

View File

@ -25,8 +25,6 @@
#include "gui/DatabaseTabWidget.h"
#include "core/Entry.h"
enum { max_length = 16*1024 };
class BrowserService : public QObject
{
Q_OBJECT

View File

@ -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

View File

@ -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;

View File

@ -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));