File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change
1
+ /** Contains predicates concerning when and where files are opened and closed. */
2
+
1
3
import python
2
4
import semmle.python.GuardedControlFlow
3
5
import semmle.python.pointsto.Filters
@@ -113,19 +115,22 @@ predicate close_method_call(CallNode call, ControlFlowNode self) {
113
115
call .getFunction ( ) .( AttrNode ) .getObject ( "close" ) = self
114
116
}
115
117
118
+ /** Holds if `close` is a function that appears to close files that are passed to it as an argument. */
116
119
predicate function_closes_file ( FunctionValue close ) {
117
120
close = Value:: named ( "os.close" )
118
121
or
119
122
function_should_close_parameter ( close .getScope ( ) )
120
123
}
121
124
125
+ /** INTERNAL - Helper predicate for `function_closes_file` */
122
126
predicate function_should_close_parameter ( Function func ) {
123
127
exists ( EssaDefinition def |
124
128
closes_file ( def ) and
125
129
def .getSourceVariable ( ) .( Variable ) .getScope ( ) = func
126
130
)
127
131
}
128
132
133
+ /** Holds if `f` opens a file, either directly or indirectly. */
129
134
predicate function_opens_file ( FunctionValue f ) {
130
135
f = Value:: named ( "open" )
131
136
or
@@ -140,6 +145,7 @@ predicate function_opens_file(FunctionValue f) {
140
145
)
141
146
}
142
147
148
+ /** Holds if `v` refers to a file opened at `open` which is subsequently returned from a function. */
143
149
predicate file_is_returned ( EssaVariable v , ControlFlowNode open ) {
144
150
exists ( NameNode n , Return ret |
145
151
var_is_open ( v , open ) and
You can’t perform that action at this time.
0 commit comments