Skip to content

Commit 84f23d2

Browse files
addaleaxevanlucas
authored andcommittedJun 12, 2018
tls: fix SSL write error handling
Fix an use-after-free bug in the TLS implementation. If we return from `DoWrite()` with an early error, we should not be storing the `WriteWrap` object and complete it again at a later point, when it has already been freed (because of the write error). This issue was reported by Jordan Zebor at F5 Networks, who also helped with investigating this bug and coming up with a reproduction. This fixes CVE-2018-7162. Fixes: https://github.com/nodejs-private/security/issues/189 PR-URL: https://github.com/nodejs-private/node-private/pull/130 Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent be103eb commit 84f23d2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed
 

‎src/stream_base.cc

+1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ void ReportWritesToJSStreamListener::OnStreamAfterReqFinished(
388388
StreamBase* stream = static_cast<StreamBase*>(stream_);
389389
Environment* env = stream->stream_env();
390390
AsyncWrap* async_wrap = req_wrap->GetAsyncWrap();
391+
CHECK(!async_wrap->persistent().IsEmpty());
391392
Local<Object> req_wrap_obj = async_wrap->object();
392393

393394
Local<Value> argv[] = {

‎src/tls_wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,10 @@ int TLSWrap::DoWrite(WriteWrap* w,
618618
if (i != count) {
619619
int err;
620620
Local<Value> arg = GetSSLError(written, &err, &error_);
621-
if (!arg.IsEmpty())
621+
if (!arg.IsEmpty()) {
622+
current_write_ = nullptr;
622623
return UV_EPROTO;
624+
}
623625

624626
pending_cleartext_input_.insert(pending_cleartext_input_.end(),
625627
&bufs[i],

0 commit comments

Comments
 (0)
Please sign in to comment.