From 16b8aca43a0acc8ec5768a82b2821dcdb2c6cf65 Mon Sep 17 00:00:00 2001 From: Bruno Jouhier Date: Sat, 7 Feb 2015 19:27:20 +0100 Subject: [PATCH] fs: properly handle fd passed to truncate() Currently, fs.truncate() silently fails when a file descriptor is passed as the first argument. This commit changes this behavior to properly call fs.ftruncate(). This commit also adds proper type checking to the callback provided to makeCallback(). PR-URL: https://github.com/joyent/node/pull/9161 Reviewed-By: Colin Ihrig Reviewed-By: Timothy J Fontaine --- lib/fs.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index bd9fde680df8..a22da4159201 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -87,10 +87,14 @@ function maybeCallback(cb) { // for callbacks that are passed to the binding layer, callbacks that are // invoked from JS already run in the proper scope. function makeCallback(cb) { - if (!util.isFunction(cb)) { + if (util.isNullOrUndefined(cb)) { return rethrow(); } + if (!util.isFunction(cb)) { + throw new TypeError('callback must be a function'); + } + return function() { return cb.apply(null, arguments); };