Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit 9b41f02

Browse files
Caleb HooverCaleb Hoover
Caleb Hoover
authored and
Caleb Hoover
committed
works again.
1 parent ba647cf commit 9b41f02

File tree

6 files changed

+106
-85
lines changed

6 files changed

+106
-85
lines changed

bin/check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ check.setFlags({
4444
verbose: argv.v,
4545
recursive: argv.r,
4646
json: !argv.j && !argv.v,
47-
debug: argv.d
47+
debug: argv.d || true
4848
});
4949
var Scope = check.Scope;
5050

check.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
22
;(function() {eval(String(require('fs').readFileSync(process.argv[1])));})()
33
*/
4-
5-
// process.on('uncaughtException', function (i) {console.log(i);});
64

75
var fs = require('fs'),
86
path = require('path'),
@@ -79,7 +77,6 @@ module.exports.setFlags = function(newFlags) {
7977
});
8078
traverse(ast, newScope);
8179

82-
8380
r = newScope.vars.module.exports;
8481

8582
} else
@@ -98,7 +95,10 @@ module.exports.setFlags = function(newFlags) {
9895

9996
find = function(r, name) {
10097
return _.find(r, function(i) {
101-
return name.indexOf(i.source.name) === 0;
98+
var r = name.indexOf(i.source.name + '.') === 0 ||
99+
name.indexOf(i.source.name + '(') === 0 ||
100+
name == i.source.name;
101+
return r;
102102
});
103103
};
104104

@@ -112,7 +112,7 @@ module.exports.setFlags = function(newFlags) {
112112
return;
113113
switch(type) {
114114
case 'SOURCE':
115-
source = find(this.reports, value);
115+
var source = find(this.reports, value);
116116
if (!source)
117117
this.reports.push({
118118
source: {
@@ -123,7 +123,7 @@ module.exports.setFlags = function(newFlags) {
123123
break;
124124
case 'SCE':
125125
case 'SCES': // Possible taint: call expression containing the source.
126-
source = find(this.reports, value);
126+
var source = find(this.reports, value);
127127
if (source) {
128128
if (!source.chain)
129129
source.chain = [];
@@ -137,7 +137,7 @@ module.exports.setFlags = function(newFlags) {
137137
case 'SASSIGN':
138138
break;
139139
case 'SINK':
140-
source = find(this.reports, value);
140+
var source = find(this.reports, value);
141141
if (source)
142142
source.sink = {
143143
name: name,
@@ -153,6 +153,7 @@ module.exports.setFlags = function(newFlags) {
153153
}
154154
break;
155155
}
156+
156157
};
157158
} else if (flags.verbose) {
158159
Scope.Scope.createNewScope = function() {
@@ -181,10 +182,9 @@ module.exports.setFlags = function(newFlags) {
181182
p = 'file://' + path.relative(Scope.Scope.baseFile.split('/').reverse().slice(1).reverse().join('/'), this.file) + ':' + p;
182183

183184

184-
console.log(' ', '[' + type + ']', p, name, value ? value : '');
185-
186-
// console.log(' ', cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
187-
// colors.grey(p), name, value ? value : '');
185+
// console.log(' ', '[' + type + ']', p, name, value ? value : '');
186+
console.log(' ', cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
187+
colors.grey(p), name, value ? value : '');
188188
};
189189
}
190190

custom.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,32 @@ var Scope = require('./scope.js');
44
var custom = module.exports.custom = [
55
function(scope, node, ce) { // http.get
66
var ceName = scope.resolve(ce.name);
7-
if (ceName != 'require(\'http\').get') {
7+
if (ceName != "require('http').get") {
88
return false;
99
}
1010

1111
var func = ce.arguments[1];
1212

1313
func.scope.sources.push(func.params[1]);
1414
func.scope.log('SOURCE', node, false, func.params[1]);
15-
traverse(func.body, func.scope);
15+
traverse(func.body, func.scope, returnCB);
16+
return true;
17+
}, function (scope, node, ce) {
18+
var ceName = scope.resolve(ce.name);
19+
if (ceName != "require('http').createServer"){
20+
return false;
21+
}
22+
23+
var func = ce.arguments[0];
24+
func.scope.sources.push(func.params[0]);
25+
func.scope.log('SOURCE', node, false, func.params[0]);
26+
traverse(func.body, func.scope, returnCB);
1627
return true;
1728
}, function(scope, node, ce) {// (new require('hapi').server()).route()
18-
if (ce.name.indexOf('require(\'hapi\').Server()') === 0)
29+
if (ce.name.indexOf("require('hapi').Server()") === 0)
1930
return false;
2031
var ceName = scope.resolve(ce.name);
21-
if (typeof ceName != "string" || ceName.split('.').slice(-1)[0] != 'route')
32+
if (typeof ceName != "string" || ceName.split('.').slice(-1)[0] != "route")
2233
return false;
2334

2435
if (ce.arguments[0]) {
@@ -32,7 +43,7 @@ function(scope, node, ce) { // http.get
3243
if (func && func.scope) {
3344
func.scope.sources.push(func.params[0]);
3445
func.scope.log('SOURCE', node, false, func.params[0]);
35-
traverse(func.body, func.scope);
46+
traverse(func.body, func.scope, returnCB);
3647
}
3748
}
3849

@@ -51,7 +62,7 @@ function(scope, node, ce) { // http.get
5162
if (func && func.scope) {
5263
func.scope.sources.push(func.params[0]);
5364
func.scope.log('SOURCE', node, false, func.params[0]);
54-
traverse(func.body, func.scope);
65+
traverse(func.body, func.scope, returnCB);
5566

5667
}
5768
}
@@ -60,7 +71,7 @@ function(scope, node, ce) { // http.get
6071

6172
}, function(scope, node, ce) {// require('fs').readFile
6273
var ceName = scope.resolve(ce.name);
63-
if (ceName != 'require(\'fs\').readFile') {
74+
if (ceName != "require(\'fs\').readFile") {
6475
return false;
6576
}
6677

@@ -69,9 +80,25 @@ function(scope, node, ce) { // http.get
6980
func.scope.sources.push(func.params[1]); // the 2nd argument is the source
7081
func.scope.log('SOURCE', node, false, func.params[1]);
7182

72-
traverse(func.body, func.scope);
83+
traverse(func.body, func.scope, returnCB);
7384
}
7485
return true;
7586
}];
7687

88+
var returnCB = function(node) {
89+
// Push scope.log. We don't want line 466 to log anything. Then pop it.
90+
var l = scope.log; scope.log = function () {};
91+
var arg = scope.resolveExpression(node.argument);
92+
scope.log = l;
93+
94+
var resolved = scope.resolve(arg);
95+
if (resolved && typeof resolved == 'string') {
96+
if (scope.isSource(resolved.name || resolved) || scope.isSource(arg.name || arg)) {
97+
if (fe.name)
98+
scope.sources.push(fe.name);
99+
scope.log('RETURN', node, fe.name, arg, resolved);
100+
}
101+
}
102+
};
103+
77104
module.exports = custom;

danger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"require\\([\\']express[\\']\\)\\.\\w+"
1313
],
1414
"sources": [
15-
"process.argv"
15+
{"process.argv": "process.argv"}
1616
]}

0 commit comments

Comments
 (0)