Skip to content

Commit

Permalink
Merge pull request aria2#1021 from aria2/fix-win-tls-read
Browse files Browse the repository at this point in the history
wintls: Potential fix for undecrypted read
  • Loading branch information
tatsuhiro-t authored Oct 7, 2017
2 parents 64fe98a + 8b32b26 commit db639dc
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/WinTLSSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,14 @@ ssize_t WinTLSSession::readData(void* data, size_t len)
return TLS_ERR_ERROR;
}

// Decrypted message successfully.
bool ate = false;
for (auto& buf : bufs) {
if (buf.BufferType == SECBUFFER_DATA && buf.cbBuffer > 0) {
decBuf_.write(buf.pvBuffer, buf.cbBuffer);
}
else if (buf.BufferType == SECBUFFER_EXTRA && buf.cbBuffer > 0) {
readBuf_.eat(readBuf_.size() - buf.cbBuffer);
ate = true;
}
// Decrypted message successfully. Inspired from curl schannel.c.
if (bufs[1].BufferType == SECBUFFER_DATA && bufs[1].cbBuffer > 0) {
decBuf_.write(bufs[1].pvBuffer, bufs[1].cbBuffer);
}
if (!ate) {
if (bufs[3].BufferType == SECBUFFER_EXTRA && bufs[3].cbBuffer > 0) {
readBuf_.eat(readBuf_.size() - bufs[3].cbBuffer);
}
else {
readBuf_.clear();
}

Expand Down

0 comments on commit db639dc

Please sign in to comment.