From c0be31f0efd162f0edd416ed23f5aac082edd2aa Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Tue, 14 Jul 2020 20:41:11 -0700 Subject: [PATCH] net: don't return the stream object from onStreamRead CallJSOnreadMethod expects the return value to be undefined or a new buffer, so make sure to return nothing, even when an error causes us to destroy the stream. Fixes: https://github.com/nodejs/node/issues/34346 PR-URL: https://github.com/nodejs/node/pull/34375 Reviewed-By: Luigi Pinca Reviewed-By: Robert Nagy Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina --- lib/internal/stream_base_commons.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index fdf540a47e08ae..cef87c4cfdf1a8 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -208,7 +208,9 @@ function onStreamRead(arrayBuffer) { } if (nread !== UV_EOF) { - return stream.destroy(errnoException(nread, 'read')); + // #34375 CallJSOnreadMethod expects the return value to be a buffer. + stream.destroy(errnoException(nread, 'read')); + return; } // Defer this until we actually emit end @@ -225,8 +227,11 @@ function onStreamRead(arrayBuffer) { // test-https-truncate test. if (handle.readStop) { const err = handle.readStop(); - if (err) - return stream.destroy(errnoException(err, 'read')); + if (err) { + // #34375 CallJSOnreadMethod expects the return value to be a buffer. + stream.destroy(errnoException(err, 'read')); + return; + } } // Push a null to signal the end of data.