-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
tls_wrap: fix BIO leak on SSL error #1244
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,8 +90,10 @@ TLSWrap::~TLSWrap() { | |
MakePending(); | ||
|
||
// And destroy | ||
while (WriteItem* wi = pending_write_items_.PopFront()) | ||
while (WriteItem* wi = pending_write_items_.PopFront()) { | ||
wi->w_->Done(UV_ECANCELED); | ||
delete wi; | ||
} | ||
|
||
ClearError(); | ||
} | ||
|
@@ -310,10 +312,12 @@ void TLSWrap::EncOut() { | |
write_req->Dispatched(); | ||
|
||
// Ignore errors, this should be already handled in js | ||
if (err) | ||
if (err) { | ||
write_req->Dispose(); | ||
else | ||
InvokeQueued(err); | ||
} else { | ||
NODE_COUNT_NET_BYTES_SENT(write_size_); | ||
} | ||
} | ||
|
||
|
||
|
@@ -335,6 +339,9 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) { | |
// Commit | ||
NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_); | ||
|
||
// Ensure that the progress will be maed and `InvokeQueued` will be called | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/maed/made/ and can you end the sentence with a dot? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, thanks. |
||
wrap->ClearIn(); | ||
|
||
// Try writing more data | ||
wrap->write_size_ = 0; | ||
wrap->EncOut(); | ||
|
@@ -375,6 +382,7 @@ Local<Value> TLSWrap::GetSSLError(int status, int* err, const char** msg) { | |
*msg = buf; | ||
} | ||
static_cast<void>(BIO_reset(bio)); | ||
BIO_free_all(bio); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean that all the BIO_new + BIO_reset calls in src/node_crypto.cc are leaking memory as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at deps/openssl/openssl/crypto/bio/bss_mem.c I'm guessing the answer is 'yes'. Instead of blindly adding BIO_free_all calls everywhere, I suggest introducing a small RAII class that fixes the issue once and for all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt we have any other places like this. |
||
|
||
return scope.Escape(exception); | ||
} | ||
|
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.
It's not clear to me why this is needed. Can you add a comment explaining it?
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.
Also, is there a reason why this can't be replaced with a call to
InvokeQueued(UV_ECANCELED)
?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.
Because
WriteWrap
s are not destroyed instream_base.cc
(and previously instream_wrap.cc
) unless the callback is invoked.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.
I'll add
InvokeQueued
here.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.
Thank you for a suggestion.