aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2018-12-02 19:53:28 +0530
committerGireesh Punathil <gpunathi@in.ibm.com>2019-03-18 10:23:08 +0530
commitdaa97df343daa79fbd49c3d77d3ddca254ca9303 (patch)
tree9a23c493905e27ec5bd778141ee8262c8f8ac2c0
parent993bdff9ff189dd32b8f782df24a1c8994392dd1 (diff)
downloadandroid-node-v8-daa97df343daa79fbd49c3d77d3ddca254ca9303.tar.gz
android-node-v8-daa97df343daa79fbd49c3d77d3ddca254ca9303.tar.bz2
android-node-v8-daa97df343daa79fbd49c3d77d3ddca254ca9303.zip
child_process: ensure message sanity at source
Error messages coming out of de-serialization at the send target is not consumable. So detect the scenario and fix it at the send source Ref: https://github.com/nodejs/node/issues/20314 PR-URL: https://github.com/nodejs/node/pull/24787 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
-rw-r--r--lib/internal/child_process.js12
-rw-r--r--test/parallel/test-child-process-fork.js6
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js
index 5bd407ca4a..549615dda8 100644
--- a/lib/internal/child_process.js
+++ b/lib/internal/child_process.js
@@ -665,6 +665,18 @@ function setupChannel(target, channel) {
if (message === undefined)
throw new ERR_MISSING_ARGS('message');
+ // Non-serializable messages should not reach the remote
+ // end point; as any failure in the stringification there
+ // will result in error message that is weakly consumable.
+ // So perform a sanity check on message prior to sending.
+ if (typeof message !== 'string' &&
+ typeof message !== 'object' &&
+ typeof message !== 'number' &&
+ typeof message !== 'boolean') {
+ throw new ERR_INVALID_ARG_TYPE(
+ 'message', ['string', 'object', 'number', 'boolean'], message);
+ }
+
// Support legacy function signature
if (typeof options === 'boolean') {
options = { swallowErrors: options };
diff --git a/test/parallel/test-child-process-fork.js b/test/parallel/test-child-process-fork.js
index 6cfeeefb51..5fee2892f3 100644
--- a/test/parallel/test-child-process-fork.js
+++ b/test/parallel/test-child-process-fork.js
@@ -49,6 +49,12 @@ assert.throws(() => n.send(), {
code: 'ERR_MISSING_ARGS'
});
+assert.throws(() => n.send(Symbol()), {
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "message" argument must be one of type string,' +
+ ' object, number, or boolean. Received type symbol',
+ code: 'ERR_INVALID_ARG_TYPE'
+});
n.send({ hello: 'world' });
n.on('exit', common.mustCall((c) => {