mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Fix possible Web UI authentication problem when using SSL (closes #941343)
This commit is contained in:
parent
c32e651c39
commit
0b13fa6914
@ -78,20 +78,20 @@ void HttpConnection::handleDownloadFailure(const QString& url,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HttpConnection::read() {
|
void HttpConnection::read() {
|
||||||
QByteArray input = m_socket->readAll();
|
static QByteArray input;
|
||||||
|
input.append(m_socket->readAll());
|
||||||
|
|
||||||
// Parse HTTP request header
|
// Parse HTTP request header
|
||||||
int header_end = input.indexOf("\r\n\r\n");
|
int header_end = input.indexOf("\r\n\r\n");
|
||||||
if (header_end < 0) {
|
if (header_end < 0) {
|
||||||
qDebug() << Q_FUNC_INFO << "missing double-CRLF";
|
// Partial request waiting for the rest
|
||||||
m_generator.setStatusLine(400, "Bad Request");
|
|
||||||
write();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QByteArray header = input.left(header_end);
|
QByteArray header = input.left(header_end);
|
||||||
m_parser.writeHeader(header);
|
m_parser.writeHeader(header);
|
||||||
if (m_parser.isError()) {
|
if (m_parser.isError()) {
|
||||||
qDebug() << Q_FUNC_INFO << "header parsing error";
|
qWarning() << Q_FUNC_INFO << "header parsing error";
|
||||||
|
input.clear();
|
||||||
m_generator.setStatusLine(400, "Bad Request");
|
m_generator.setStatusLine(400, "Bad Request");
|
||||||
write();
|
write();
|
||||||
return;
|
return;
|
||||||
@ -99,29 +99,30 @@ void HttpConnection::read() {
|
|||||||
|
|
||||||
// Parse HTTP request message
|
// Parse HTTP request message
|
||||||
if (m_parser.header().hasContentLength()) {
|
if (m_parser.header().hasContentLength()) {
|
||||||
QByteArray message = input.mid(header_end + 4);
|
const int expected_length = m_parser.header().contentLength();
|
||||||
int expected_length = m_parser.header().contentLength();
|
QByteArray message = input.mid(header_end + 4, expected_length);
|
||||||
|
input = input.mid(header_end + 4 + expected_length);
|
||||||
|
|
||||||
if (expected_length > 100000) {
|
if (expected_length > 100000) {
|
||||||
|
qWarning() << "Bad request: message too long";
|
||||||
m_generator.setStatusLine(400, "Bad Request");
|
m_generator.setStatusLine(400, "Bad Request");
|
||||||
|
input.clear();
|
||||||
write();
|
write();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_reading = true;
|
if (message.length() < expected_length) {
|
||||||
while (message.length() < expected_length && is_reading) {
|
// Message too short, waiting for the rest
|
||||||
disconnect(m_socket, SIGNAL(readyRead()), this, SLOT(read()));
|
return;
|
||||||
is_reading = m_socket->waitForReadyRead(2000);
|
|
||||||
if (is_reading) {
|
|
||||||
message.append(m_socket->readAll());
|
|
||||||
}
|
|
||||||
connect(m_socket, SIGNAL(readyRead()), this, SLOT(read()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parser.writeMessage(message);
|
m_parser.writeMessage(message);
|
||||||
|
} else {
|
||||||
|
input.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_parser.isError()) {
|
if (m_parser.isError()) {
|
||||||
qDebug() << Q_FUNC_INFO << "message parsing error";
|
qWarning() << Q_FUNC_INFO << "message parsing error";
|
||||||
m_generator.setStatusLine(400, "Bad Request");
|
m_generator.setStatusLine(400, "Bad Request");
|
||||||
write();
|
write();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user