From 2ac7de02c42654e4e80e346e5d560f7cc01d4553 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 25 Sep 2015 20:48:56 +0200 Subject: [PATCH] Fix infinite loop with zero-length options. The bundled copy of GYP enters an infinite loop when it encounters a zero-length option so ensure those don't get through. The root cause is a bad guard in gyp/pylib/gyp/input.py that doesn't take into account that `'' in 'whatever'` evaluates to True. Upstream fix at https://codereview.chromium.org/1364373004/. Fixes: https://github.com/nodejs/node-gyp/issues/744 PR-URL: https://github.com/nodejs/node-gyp/pull/745 Reviewed-By: Nathan Rajlich --- lib/node-gyp.js | 4 +++- test/test-options.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/test-options.js diff --git a/lib/node-gyp.js b/lib/node-gyp.js index d6d6509a7a..b84f17d7e2 100644 --- a/lib/node-gyp.js +++ b/lib/node-gyp.js @@ -164,7 +164,9 @@ proto.parseArgv = function parseOpts (argv) { } else { // add the user-defined options to the config name = name.substring(npm_config_prefix.length) - this.opts[name] = val + // gyp@741b7f1 enters an infinite loop when it encounters + // zero-length options so ensure those don't get through. + if (name) this.opts[name] = val } }, this) diff --git a/test/test-options.js b/test/test-options.js new file mode 100644 index 0000000000..5ce314f541 --- /dev/null +++ b/test/test-options.js @@ -0,0 +1,20 @@ +'use strict'; + +var test = require('tape') +var gyp = require('../lib/node-gyp') + +test('options in environment', function (t) { + t.plan(1) + + // Zero-length keys should get filtered out. + process.env.npm_config_ = '42' + // Other keys should get added. + process.env.npm_config_x = '42' + // Except loglevel. + process.env.npm_config_loglevel = 'debug' + + var g = gyp(); + g.parseArgv(['rebuild']) // Also sets opts.argv. + + t.deepEqual(Object.keys(g.opts).sort(), ['argv', 'x']) +})