Skip to content

Commit ea0f6a3

Browse files
committed
refactor into maybePromisified predicate
1 parent e8dc77d commit ea0f6a3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,22 +586,27 @@ module NodeJSLib {
586586
}
587587
}
588588

589+
/**
590+
* Gets a possibly promisified (using `util.promisify`) version of the input `func`.
591+
*/
592+
DataFlow::SourceNode maybePromisified(DataFlow::SourceNode func) {
593+
result = func
594+
or
595+
exists(DataFlow::CallNode promisify |
596+
promisify = DataFlow::moduleMember("util", "promisify").getACall()
597+
|
598+
result = promisify and promisify.getArgument(0).getALocalSource() = func
599+
)
600+
}
601+
589602
/**
590603
* A call to a method from module `child_process`.
591604
*/
592605
private class ChildProcessMethodCall extends SystemCommandExecution, DataFlow::CallNode {
593606
string methodName;
594607

595608
ChildProcessMethodCall() {
596-
this = DataFlow::moduleMember("child_process", methodName).getACall()
597-
or
598-
exists(DataFlow::CallNode promisify |
599-
promisify = DataFlow::moduleMember("util", "promisify").getACall()
600-
|
601-
this = promisify.getACall() and
602-
promisify.getArgument(0).getALocalSource() =
603-
DataFlow::moduleMember("child_process", methodName)
604-
)
609+
this = maybePromisified(DataFlow::moduleMember("child_process", methodName)).getACall()
605610
}
606611

607612
private DataFlow::Node getACommandArgument(boolean shell) {

0 commit comments

Comments
 (0)