-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid ArgumentOutOfRangeException while processing invalid or incomplete TLS frame #63184
Conversation
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsThis change fixes issue reported in #62109. The issue has long summary describing what is going on - based on dump provided by the reporter. In essence, I modified the fixes #62109
|
src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Implementation.cs
Show resolved
Hide resolved
Since we are changing this code anyway: I don't understand why we have the InternalFillHandshakeBuffferAsync helper here. What is this accomplishing, vs just directly awaiting the task returned by ReadAsync? The async machinery already optimizes for the sync completion case. I suppose perhaps there is some benefit in avoiding the very small cost of async method setup in the case where we don't need to read at all, but (a) I'm quite skeptical that this cost matters, and (b) even if we want to optimize for it, we can achieve the same result much more easily. Looking back at the history here, this seems to have happened because we basically copied this code from FillBufferAsync, and that's what FillBufferAsync used to do. But FillBufferAsync was changed to not do this a long time ago. (Also, FillBufferAsync seems to be not used at all anymore, and should be removed.) |
yes, I was thinking about InternalFillHandshakeBuffferAsync, but decided not to change it with this change. It is independent IMHO and would complicate servicing if we would think about it. It seems like was |
Looks like I open #52037 while back for the buffers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change fixes issue reported in #62109. The issue has long summary describing what is going on - based on dump provided by the reporter.
In essence,
FillHandshakeBufferAsync
can "silently fail" on EOF and we can create ArrayBuffer with negative length. Added test would throwArgumentOutOfRangeException
on release builds or hitAssert
with debug builds.I modified the
FillHandshakeBufferAsync
to consistently throw if EOF is reached before request bytes are accumulated. This was already there in few places but we missed the case when read would finish synchronously.fixes #62109