_stream_wrap: prevent use after free in TLS
authorFedor Indutny <fedor@indutny.com>
Sat, 6 Jun 2015 22:37:35 +0000 (00:37 +0200)
committerFedor Indutny <fedor@indutny.com>
Wed, 1 Jul 2015 03:09:22 +0000 (20:09 -0700)
commit9180140231823f8a9cd6c6d7cf05d809d76299f2
tree1fe4ff09763d4b8b5470dd28ff57aaf9008d6218
parent6c61ca5325a411c4b64177c5bca58030ea5b97a4
_stream_wrap: prevent use after free in TLS

Queued write requests should be invoked on handle close, otherwise the
"consumer" might be already destroyed when the write callbacks of the
"consumed" handle will be invoked. Same applies to the shutdown
requests.

Make sure to "move" away socket from server to not break the
`connections` counter in `net.js`. Otherwise it might not call `close`
callback, or call it too early.

Fix: https://github.com/iojs/io.js/issues/1696
PR-URL: https://github.com/nodejs/io.js/pull/1910
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
lib/_stream_wrap.js
lib/_tls_wrap.js
src/js_stream.cc
src/tls_wrap.cc
test/parallel/test-stream-wrap.js [new file with mode: 0644]
test/parallel/test-tls-connect-given-socket.js
test/parallel/test-tls-destroy-whilst-write.js [new file with mode: 0644]