Skip to content

Commit

Permalink
Changed the max length define
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Apr 1, 2018
1 parent 8c6a7ce commit d666625
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
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 = 1024*1024 };

class BrowserService : public QObject
{
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/browser/NativeMessagingBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <sys/socket.h>
#endif

static const int NATIVE_MSG_MAX_LENGTH = 1024*1024;

class NativeMessagingBase : public QObject
{
Q_OBJECT
Expand Down
16 changes: 7 additions & 9 deletions src/browser/NativeMessagingHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,17 @@ void NativeMessagingHost::newLocalConnection()
void NativeMessagingHost::newLocalMessage()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(QObject::sender());
if (socket) {
socket->setReadBufferSize(max_length);
int socketDesc = socket->socketDescriptor();
if (socketDesc) {
int max = max_length;
res = setsockopt(socketDesc, SOL_SOCKET, SO_SNDBUF, &max, sizeof(max));
}
}

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

0 comments on commit d666625

Please sign in to comment.