[Go] Trouble getting the resolved type of an argument from nested function #15886
-
Hi, I am facing an issue to obtain the resolved type of an argument in the following situation (simplified from what some flavour of the Kubernetes client-go do) : package main
type Object interface{ Bar() bool }
type SpecificObject struct {
Foo string
otherFoo string
}
func (so SpecificObject) Bar() bool { return true }
func cacheReader(key string) interface{} {
if len(key) > 0 {
// The details don't matter so much here, what counts is that an interface{} is returned
return new(interface{})
}
return nil
}
func ReadObject(key string, obj Object) {
obj = cacheReader(key).(Object)
}
func ReadObjectWrapper(obj Object) {
ReadObject("foobar", obj)
}
func ReadObjectAfterCheck(obj Object) {
if obj.Bar() { // The nature of the check does not matter here
ReadObjectWrapper(obj)
}
}
func sink(s string) { /**/ }
func main() {
so := &SpecificObject{Foo: "Bar"}
ReadObjectAfterCheck(so)
sink(so.otherFoo)
} With the following query: /**
* @kind path-problem
*/
import go
import DataFlow
class MySource extends Function {
MySource() { this.getName() = "ReadObject" }
FunctionInput getInput() { result.isParameter(1) }
FunctionOutput getOutput() { result.isParameter(1) }
}
private module TestFlow implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
exists(MySource ms | node = ms.getOutput().getNode(ms.getACall()))
}
predicate isSink(DataFlow::Node node) {
exists(Function sink | sink.getName() = "sink" and sink.getACall().getAnArgument() = node)
}
}
module Flow = TaintTracking::Global<TestFlow>;
import Flow::PathGraph
from Flow::PathNode source, Flow::PathNode sink, Type t
where Flow::flowPath(source, sink) and t = source.getNode().getType()
select source.getNode(), source, sink, "$@ (with type $@) -> $@", source.getNode(), "__source__", t,
t.pp(), sink.getNode(), "__sink__" This returns: It's not clear to me if the expectation I have are misguided or if some additional bits (like a flow to model |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
Thank you for including a minimized example and a working query, which made it very easy to understand your question. The problem is that your source, which is
I hope that this approach works for you. I have been very vague on exactly how to define the source because I am not sure and it depends a bit on the exact details of your situation, so do try some different things and ask more questions if you need more help with that bit. |
Beta Was this translation helpful? Give feedback.
Good point. Try this: