diff options
author | Trevor Norris <trev.norris@gmail.com> | 2016-04-13 13:16:42 -0600 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2016-05-24 14:40:22 -0600 |
commit | c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad (patch) | |
tree | 2f24e1329abb6b5432273246b4754ec44e7b3e8a /test | |
parent | 13e5d4f32014e3426142580a699d0ffdf02db26a (diff) | |
download | android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.tar.gz android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.tar.bz2 android-node-v8-c0e6c668e6e6f0ba6a924a5b83ff1ca5434d14ad.zip |
src: no abort from getter if object isn't wrapped
v8::Object::GetAlignedPointerFromInternalField() returns a random value
if Wrap() hasn't been run on the object handle. Causing v8 to abort if
certain getters are accessed. It's possible to access these getters and
functions during class construction through the AsyncWrap init()
callback, and also possible in a subset of those scenarios while running
the persistent handle visitor.
Mitigate this issue by manually setting the internal aligned pointer
field to nullptr in the BaseObject constructor and add necessary logic
to return appropriate values when nullptr is encountered.
PR-URL: https://github.com/nodejs/node/pull/6184
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stream-base-no-abort.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/parallel/test-stream-base-no-abort.js b/test/parallel/test-stream-base-no-abort.js new file mode 100644 index 0000000000..d2d8702676 --- /dev/null +++ b/test/parallel/test-stream-base-no-abort.js @@ -0,0 +1,58 @@ +'use strict'; + +const async_wrap = process.binding('async_wrap'); +const uv = process.binding('uv'); +const assert = require('assert'); +const common = require('../common'); +const dgram = require('dgram'); +const fs = require('fs'); +const net = require('net'); +const tls = require('tls'); +const providers = Object.keys(async_wrap.Providers); +var flags = 0; + +// Make sure all asserts have run at least once. +process.on('exit', () => assert.equal(flags, 0b111)); + +function init(id, provider) { + this._external; // Test will abort if nullptr isn't properly checked. + switch (providers[provider]) { + case 'TCPWRAP': + assert.equal(this.fd, uv.UV_EINVAL); + flags |= 0b1; + break; + case 'TLSWRAP': + assert.equal(this.fd, uv.UV_EINVAL); + flags |= 0b10; + break; + case 'UDPWRAP': + assert.equal(this.fd, uv.UV_EBADF); + flags |= 0b100; + break; + } +} + +async_wrap.setupHooks({ init }); +async_wrap.enable(); + +const checkTLS = common.mustCall(function checkTLS() { + const options = { + key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), + cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem') + }; + const server = tls.createServer(options, () => {}) + .listen(common.PORT, function() { + tls.connect(common.PORT, { rejectUnauthorized: false }, function() { + this.destroy(); + server.close(); + }); + }); +}); + +const checkTCP = common.mustCall(function checkTCP() { + net.createServer(() => {}).listen(common.PORT, function() { + this.close(checkTLS); + }); +}); + +dgram.createSocket('udp4').close(checkTCP); |