diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-01-21 12:32:07 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-01-21 13:54:26 (GMT) |
commit | 2dd3a061ea0a0f1361c3f12d6859a4b9cdcae7bb (patch) | |
tree | b21b7c0c1c00b82dad54bea5efc6447dfaf0fba3 | |
parent | c2573f74fb8a09484b385e4469d887bb0fea8cb9 (diff) | |
download | Qt-2dd3a061ea0a0f1361c3f12d6859a4b9cdcae7bb.zip Qt-2dd3a061ea0a0f1361c3f12d6859a4b9cdcae7bb.tar.gz Qt-2dd3a061ea0a0f1361c3f12d6859a4b9cdcae7bb.tar.bz2 |
QSslSocket: Take better care on how we use the SSL buffers
.. and breaking out of a loop where we should.
Reviewed-by: thiago
-rw-r--r-- | src/network/ssl/qsslsocket_openssl.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/network/ssl/qsslsocket_openssl.cpp b/src/network/ssl/qsslsocket_openssl.cpp index de1583e..892d330 100644 --- a/src/network/ssl/qsslsocket_openssl.cpp +++ b/src/network/ssl/qsslsocket_openssl.cpp @@ -553,6 +553,12 @@ void QSslSocketBackendPrivate::transmit() #endif writeBuffer.free(writtenBytes); totalBytesWritten += writtenBytes; + + if (writtenBytes < nextDataBlockSize) { + // break out of the writing loop and try again after we had read + transmitting = true; + break; + } } if (totalBytesWritten > 0) { @@ -586,12 +592,26 @@ void QSslSocketBackendPrivate::transmit() while ((pendingBytes = plainSocket->bytesAvailable()) > 0) { // Read encrypted data from the socket into a buffer. data.resize(pendingBytes); - int decryptedBytesRead = plainSocket->read(data.data(), pendingBytes); + // just peek() here because q_BIO_write could write less data than expected + int encryptedBytesRead = plainSocket->peek(data.data(), pendingBytes); #ifdef QSSLSOCKET_DEBUG - qDebug() << "QSslSocketBackendPrivate::transmit: read" << decryptedBytesRead << "encrypted bytes from the socket"; + qDebug() << "QSslSocketBackendPrivate::transmit: read" << encryptedBytesRead << "encrypted bytes from the socket"; #endif // Write encrypted data from the buffer into the read BIO. - q_BIO_write(readBio, data.constData(), decryptedBytesRead); + int writtenToBio = q_BIO_write(readBio, data.constData(), encryptedBytesRead); + + // do the actual read() here and throw away the results. + if (writtenToBio > 0) { + // ### TODO: make this cheaper by not making it memcpy. E.g. make it work with data=0x0 or make it work with seek + plainSocket->read(data.data(), writtenToBio); + } else { + // ### Better error handling. + q->setErrorString(QSslSocket::tr("Unable to decrypt data: %1").arg(SSL_ERRORSTR())); + q->setSocketError(QAbstractSocket::UnknownSocketError); + emit q->error(QAbstractSocket::UnknownSocketError); + return; + } + transmitting = true; } |