refactor into maybePromisified predicate

This commit is contained in:
Erik Krogh Kristensen
2020-04-17 09:50:08 +02:00
parent e8dc77d508
commit ea0f6a367d

View File

@@ -586,6 +586,19 @@ module NodeJSLib {
}
}
/**
* Gets a possibly promisified (using `util.promisify`) version of the input `func`.
*/
DataFlow::SourceNode maybePromisified(DataFlow::SourceNode func) {
result = func
or
exists(DataFlow::CallNode promisify |
promisify = DataFlow::moduleMember("util", "promisify").getACall()
|
result = promisify and promisify.getArgument(0).getALocalSource() = func
)
}
/**
* A call to a method from module `child_process`.
*/
@@ -593,15 +606,7 @@ module NodeJSLib {
string methodName;
ChildProcessMethodCall() {
this = DataFlow::moduleMember("child_process", methodName).getACall()
or
exists(DataFlow::CallNode promisify |
promisify = DataFlow::moduleMember("util", "promisify").getACall()
|
this = promisify.getACall() and
promisify.getArgument(0).getALocalSource() =
DataFlow::moduleMember("child_process", methodName)
)
this = maybePromisified(DataFlow::moduleMember("child_process", methodName)).getACall()
}
private DataFlow::Node getACommandArgument(boolean shell) {