mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-20 20:54:38 -04:00
Socket buffer size fix (#1720)
This commit is contained in:
parent
0650b3084e
commit
3a92e4aab9
5 changed files with 24 additions and 5 deletions
|
@ -20,6 +20,7 @@
|
||||||
#include <QJsonParseError>
|
#include <QJsonParseError>
|
||||||
#include "BrowserAction.h"
|
#include "BrowserAction.h"
|
||||||
#include "BrowserSettings.h"
|
#include "BrowserSettings.h"
|
||||||
|
#include "NativeMessagingBase.h"
|
||||||
#include "sodium.h"
|
#include "sodium.h"
|
||||||
#include "sodium/crypto_box.h"
|
#include "sodium/crypto_box.h"
|
||||||
#include "sodium/randombytes.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> sk(sa.cbegin(), sa.cend());
|
||||||
|
|
||||||
std::vector<unsigned char> e;
|
std::vector<unsigned char> e;
|
||||||
e.resize(max_length);
|
e.resize(NATIVE_MSG_MAX_LENGTH);
|
||||||
|
|
||||||
if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
|
if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
|
||||||
return QString();
|
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> sk(sa.cbegin(), sa.cend());
|
||||||
|
|
||||||
std::vector<unsigned char> d;
|
std::vector<unsigned char> d;
|
||||||
d.resize(max_length);
|
d.resize(NATIVE_MSG_MAX_LENGTH);
|
||||||
|
|
||||||
if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
|
if (m.empty() || n.empty() || ck.empty() || sk.empty()) {
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
#include "gui/DatabaseTabWidget.h"
|
#include "gui/DatabaseTabWidget.h"
|
||||||
#include "core/Entry.h"
|
#include "core/Entry.h"
|
||||||
|
|
||||||
enum { max_length = 16*1024 };
|
|
||||||
|
|
||||||
class BrowserService : public QObject
|
class BrowserService : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -32,6 +32,13 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#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
|
class NativeMessagingBase : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -142,11 +142,17 @@ void NativeMessagingHost::newLocalConnection()
|
||||||
void NativeMessagingHost::newLocalMessage()
|
void NativeMessagingHost::newLocalMessage()
|
||||||
{
|
{
|
||||||
QLocalSocket* socket = qobject_cast<QLocalSocket*>(QObject::sender());
|
QLocalSocket* socket = qobject_cast<QLocalSocket*>(QObject::sender());
|
||||||
|
|
||||||
if (!socket || socket->bytesAvailable() <= 0) {
|
if (!socket || socket->bytesAvailable() <= 0) {
|
||||||
return;
|
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();
|
QByteArray arr = socket->readAll();
|
||||||
if (arr.isEmpty()) {
|
if (arr.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,6 +22,13 @@ NativeMessagingHost::NativeMessagingHost() : NativeMessagingBase()
|
||||||
{
|
{
|
||||||
m_localSocket = new QLocalSocket();
|
m_localSocket = new QLocalSocket();
|
||||||
m_localSocket->connectToServer(getLocalServerPath());
|
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
|
#ifdef Q_OS_WIN
|
||||||
m_running.store(true);
|
m_running.store(true);
|
||||||
m_future = QtConcurrent::run(this, static_cast<void(NativeMessagingHost::*)()>(&NativeMessagingHost::readNativeMessages));
|
m_future = QtConcurrent::run(this, static_cast<void(NativeMessagingHost::*)()>(&NativeMessagingHost::readNativeMessages));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue