Skip to content

Commit

Permalink
Fix infinite loop with zero-length options.
Browse files Browse the repository at this point in the history
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: #744
PR-URL: #745
Reviewed-By: Nathan Rajlich <[email protected]>
  • Loading branch information
bnoordhuis committed Sep 25, 2015
1 parent 101bed6 commit 2ac7de0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions test/test-options.js
Original file line number Diff line number Diff line change
@@ -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'])
})

0 comments on commit 2ac7de0

Please sign in to comment.