Skip to content

Determine if a function is called with a specific value as parameter based on the value of another variable #60

Answered by asgerf
esarafianou asked this question in General
Discussion options

You must be logged in to vote

Hi,

It sounds like to you can use ConditionGuardNode. It's a control-flow node that occurs in places where it's known that a certain expression is true or false. We can use .dominates() to check whether it dominates another node ("dominates" means all paths to the other node must first go through the guard node).

Here's a query that flags the first example but not the second:

import javascript

Function validateFn() {
    result.getName() = "validate"
}

ConditionGuardNode guardNode() {
    result.getTest() = validateFn().getParameterByName("a").getVariable().getAnAccess() and
    result.getOutcome() = false
}

predicate isGuarded(ControlFlowNode node) {
    guardNode().dominates(node.get…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@esarafianou
Comment options

@asgerf
Comment options

@esarafianou
Comment options

@asgerf
Comment options

Answer selected by nicowaisman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants