bug 1029163 - part 1 nsPipe can turn failures into OK, consider that in the tlsproxy code r=hurley

This commit is contained in:
Patrick McManus 2014-06-24 07:56:07 -04:00
Родитель 68ae085486
Коммит 548c66439c
1 изменённых файлов: 14 добавлений и 2 удалений

Просмотреть файл

@ -261,8 +261,9 @@ TLSFilterTransaction::OnWriteSegment(char *aData,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
// this will call through to FilterRead to get data from the higher // this will call through to FilterInput to get data from the higher
// level connection before removing the local TLS layer // level connection before removing the local TLS layer
mFilterReadCode = NS_OK;
int32_t bytesRead = PR_Read(mFD, aData, aCount); int32_t bytesRead = PR_Read(mFD, aData, aCount);
if (bytesRead == -1) { if (bytesRead == -1) {
if (PR_GetError() == PR_WOULD_BLOCK_ERROR) { if (PR_GetError() == PR_WOULD_BLOCK_ERROR) {
@ -271,6 +272,13 @@ TLSFilterTransaction::OnWriteSegment(char *aData,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
*outCountRead = bytesRead; *outCountRead = bytesRead;
if (NS_SUCCEEDED(mFilterReadCode) && !bytesRead) {
LOG(("TLSFilterTransaction::OnWriteSegment %p "
"Second layer of TLS stripping results in STREAM_CLOSED\n", this));
mFilterReadCode = NS_BASE_STREAM_CLOSED;
}
LOG(("TLSFilterTransaction::OnWriteSegment %p rv=%x didread=%d " LOG(("TLSFilterTransaction::OnWriteSegment %p rv=%x didread=%d "
"2 layers of ssl stripped to plaintext\n", this, mFilterReadCode, bytesRead)); "2 layers of ssl stripped to plaintext\n", this, mFilterReadCode, bytesRead));
return mFilterReadCode; return mFilterReadCode;
@ -286,7 +294,7 @@ TLSFilterTransaction::FilterInput(char *aBuf, int32_t aAmount)
uint32_t outCountRead = 0; uint32_t outCountRead = 0;
mFilterReadCode = mSegmentWriter->OnWriteSegment(aBuf, aAmount, &outCountRead); mFilterReadCode = mSegmentWriter->OnWriteSegment(aBuf, aAmount, &outCountRead);
if (NS_SUCCEEDED(mFilterReadCode) && outCountRead) { if (NS_SUCCEEDED(mFilterReadCode) && outCountRead) {
LOG(("TLSFilterTransaction::FilterRead rv=%x read=%d input from net " LOG(("TLSFilterTransaction::FilterInput rv=%x read=%d input from net "
"1 layer stripped, 1 still on\n", mFilterReadCode, outCountRead)); "1 layer stripped, 1 still on\n", mFilterReadCode, outCountRead));
if (mReadSegmentBlocked) { if (mReadSegmentBlocked) {
mNudgeCounter = 0; mNudgeCounter = 0;
@ -338,6 +346,10 @@ TLSFilterTransaction::WriteSegments(nsAHttpSegmentWriter *aWriter,
mSegmentWriter = aWriter; mSegmentWriter = aWriter;
nsresult rv = mTransaction->WriteSegments(this, aCount, outCountWritten); nsresult rv = mTransaction->WriteSegments(this, aCount, outCountWritten);
if (NS_SUCCEEDED(rv) && NS_FAILED(mFilterReadCode) && !(*outCountWritten)) {
// nsPipe turns failures into silent OK.. undo that!
rv = mFilterReadCode;
}
LOG(("TLSFilterTransaction %p called trans->WriteSegments rv=%x %d\n", LOG(("TLSFilterTransaction %p called trans->WriteSegments rv=%x %d\n",
this, rv, *outCountWritten)); this, rv, *outCountWritten));
return rv; return rv;