You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately this will only give the expression in the argument, not the values which could be passed to it. So we use local data flow to find all expressions that flow into the argument:
94
96
95
97
.. code-block:: ql
96
98
97
-
import csharp
99
+
import python
100
+
import semmle.python.dataflow.new.DataFlow
101
+
import semmle.python.ApiGraphs
98
102
99
-
from Method fileOpen, MethodCall call, Expr src
100
-
where fileOpen.hasQualifiedName("System.IO.File.Open")
101
-
and call.getTarget() = fileOpen
102
-
and DataFlow::localFlow(DataFlow::exprNode(src), DataFlow::exprNode(call.getArgument(0)))
103
-
select src
103
+
from DataFlow::CallCfgNode call, DataFlow::ExprNode expr
Then we can make the source more specific, for example an access to a public parameter. This query finds instances where a public parameter is used to open a file:
109
+
Then we can make the source more specific, for example a parameter to a function or method. This query finds instances where a parameter is used as the name when opening a file:
106
110
107
111
.. code-block:: ql
108
112
109
-
import csharp
113
+
import python
114
+
import semmle.python.dataflow.new.DataFlow
115
+
import semmle.python.ApiGraphs
110
116
111
-
from Method fileOpen, MethodCall call, Parameter p
112
-
where fileOpen.hasQualifiedName("System.IO.File.Open")
113
-
and call.getTarget() = fileOpen
114
-
and DataFlow::localFlow(DataFlow::parameterNode(p), DataFlow::exprNode(call.getArgument(0)))
115
-
and call.getEnclosingCallable().(Member).isPublic()
116
-
select p, "Opening a file from a public method."
117
+
from DataFlow::CallCfgNode call, DataFlow::ParameterNode p
0 commit comments