summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2017-12-02 10:04:50 -0500
committercjihrig <cjihrig@gmail.com>2017-12-06 12:02:47 -0500
commitcd174df353e78cde9181299adbf501a4a694dee8 (patch)
tree9a212c68cbdf28588d78b5ea8c396abf9cdf7f8d /lib
parent817d4adb47b0bbc03733f67a48b15287092b3909 (diff)
downloadandroid-node-v8-cd174df353e78cde9181299adbf501a4a694dee8.tar.gz
android-node-v8-cd174df353e78cde9181299adbf501a4a694dee8.tar.bz2
android-node-v8-cd174df353e78cde9181299adbf501a4a694dee8.zip
buffer: throw on failed fill attempts
If fill() attempts to write a string to a buffer, but fails silently, then uninitialized memory could be leaked. This commit causes fill() to throw if the string write operation fails. Refs: https://github.com/nodejs/node/issues/17423 PR-URL: https://github.com/nodejs/node/pull/17427 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/buffer.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/buffer.js b/lib/buffer.js
index 8899d260ad..40aaf37e09 100644
--- a/lib/buffer.js
+++ b/lib/buffer.js
@@ -892,8 +892,12 @@ function fill_(buf, val, start, end, encoding) {
start = start >>> 0;
end = end === undefined ? buf.length : end >>> 0;
+ const fillLength = bindingFill(buf, val, start, end, encoding);
- return bindingFill(buf, val, start, end, encoding);
+ if (fillLength === -1)
+ throw new errors.TypeError('ERR_INVALID_ARG_VALUE', 'value', val);
+
+ return fillLength;
}