Skip to content

Change definition of getFactoryNodeInternal #19359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dynamically determine the callback argument's position
An additional parameter may be anywhere in the
parameter list and shift around the exact index of
the callback argument in the parameter list.

So, "dynamically" determine the index by type-checking
a parameter in the parameter list.

Note 1: There may be multiple matches since we're
using `_` (don't care) as the argument index.

Note 2: We could have used DataFlow::InvokeNode.getCallback
if the supertype were not CallExpr, but jumping to
data flow node is an overkill here.
  • Loading branch information
jeongsoolee09 committed Apr 23, 2025
commit f0dfa51fb9e10fb61130fbc5e30718916c421826
4 changes: 3 additions & 1 deletion javascript/ql/lib/semmle/javascript/AMD.qll
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class AmdModuleDefinition extends CallExpr instanceof AmdModuleDefinition::Range
Function getFactoryFunction() { TValueNode(result) = this.getFactoryNodeInternal() }

private EarlyStageNode getFactoryNodeInternal() {
result = TValueNode(this.getArgument(1))
exists(Function factoryFunction | factoryFunction = this.getArgument(_) |
result = TValueNode(factoryFunction)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restriction to Function here is too restrictive as we may need to follow some local flow steps before we get to the function (see the recursive case below). Some tests are failing because of this. Could you try simply changing getLastArgument() to getArgument(_)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the construction of TValueNode to TValueNode(this.getArgument(_)).

or
DataFlow::localFlowStep(result, this.getFactoryNodeInternal())
}
Expand Down
Loading