Skip to content

Commit

Permalink
Simplify checkPath internal func (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
picatz authored Jan 3, 2024
1 parent fbeb379 commit 7bc76a8
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,16 @@ func checkPath(path callgraph.Path, sources Sources) (bool, string, ssa.Value) {
return false, "", nil
}

// Extract the last call from the path, along with its arguments,
// to check if any of the given sources were used to obtain it.
var (
lastCall = path.Last()
lastCallArgs = lastCall.Site.Common().Args
visited = valueSet{}
)

// Check if any of the given sources were used to obtain the last call
// in the path. If so, we can assume the path is tainted.
//
// TODO: when non-function sinks are supported, we will need to handle
// them differently here.
for _, lastCallArg := range lastCallArgs {
tainted, src, tv := checkSSAValue(path, sources, lastCallArg, visited)
if tainted {
return true, src, tv
}
// Value set used to keep track of values which were already visited
// during the taint analysis. This prevents cyclic calls from crashing
// the program.
visited := valueSet{}

// Start at last call from the path to see if any of the given sources were used
// along with it to perform an action (e.g. SQL query).
tainted, src, tv := checkSSAValue(path, sources, path.Last().Site.Value(), visited)
if tainted {
return true, src, tv
}

return false, "", nil
Expand Down

0 comments on commit 7bc76a8

Please sign in to comment.