From 4c207d9b849861876bfe589da5495df332af01c3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 13 Jan 2019 17:09:15 +0100 Subject: [PATCH] test: do not use uninitialized memory in common flags check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only use the amount of data that was actually read from the test file. Otherwise, there is a small risk of getting false positives, and generally reading uninitialized memory makes using automated memory error detection tools harder. PR-URL: https://github.com/nodejs/node/pull/25475 Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau Reviewed-By: Tobias Nießen Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/common/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/common/index.js b/test/common/index.js index 0fcbe88adb10ca..2fdac3d2e5e894 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -57,9 +57,9 @@ if (process.argv.length === 2 && const bytesToRead = 1500; const buffer = Buffer.allocUnsafe(bytesToRead); const fd = fs.openSync(module.parent.filename, 'r'); - fs.readSync(fd, buffer, 0, bytesToRead); + const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead); fs.closeSync(fd); - const source = buffer.toString(); + const source = buffer.toString('utf8', 0, bytesRead); const flagStart = source.indexOf('// Flags: --') + 10; if (flagStart !== 9) {