@@ -113,43 +113,59 @@ predicate checksPath(Expr check, Expr checkPath) {
113
113
)
114
114
}
115
115
116
+ pragma [ nomagic]
117
+ predicate checkPathControlsUse ( Expr check , Expr checkPath , Expr use ) {
118
+ exists ( GuardCondition guard | referenceTo ( check , guard .getAChild * ( ) ) |
119
+ guard .controls ( use .getBasicBlock ( ) , _)
120
+ ) and
121
+ checksPath ( pragma [ only_bind_into ] ( check ) , checkPath )
122
+ }
123
+
124
+ pragma [ nomagic]
125
+ predicate fileNameOperationControlsUse ( Expr check , Expr checkPath , Expr use ) {
126
+ exists ( GuardCondition guard | referenceTo ( check , guard .getAChild * ( ) ) |
127
+ guard .controls ( use .getBasicBlock ( ) , _)
128
+ ) and
129
+ pragma [ only_bind_into ] ( check ) = filenameOperation ( checkPath )
130
+ }
131
+
116
132
predicate checkUse ( Expr check , Expr checkPath , FunctionCall use , Expr usePath ) {
133
+ // `check` is part of a guard that controls `use`
134
+ checkPathControlsUse ( check , checkPath , use ) and
117
135
// `check` looks like a check on a filename
118
136
checksPath ( check , checkPath ) and
119
137
// `op` looks like an operation on a filename
120
138
use = filenameOperation ( usePath )
121
139
or
140
+ // `check` is part of a guard that controls `use`
141
+ fileNameOperationControlsUse ( check , checkPath , use ) and
122
142
// another filename operation (null pointers can indicate errors)
123
143
check = filenameOperation ( checkPath ) and
124
144
// `op` looks like a sensitive operation on a filename
125
145
use = sensitiveFilenameOperation ( usePath )
126
146
}
127
147
128
148
pragma [ noinline]
129
- Expr getACheckedPath ( Expr check , SsaDefinition def , StackVariable v ) {
130
- checkUse ( check , result , _, _) and
131
- def .getAUse ( v ) = result
149
+ predicate isCheckedPath (
150
+ Expr check , SsaDefinition def , StackVariable v , FunctionCall use , Expr usePath , Expr checkPath
151
+ ) {
152
+ checkUse ( check , checkPath , use , usePath ) and
153
+ def .getAUse ( v ) = checkPath
132
154
}
133
155
134
156
pragma [ noinline]
135
- Expr getAUsedPath ( FunctionCall use , SsaDefinition def , StackVariable v ) {
136
- checkUse ( _, _, use , result ) and
137
- def .getAUse ( v ) = result
157
+ predicate isUsedPath (
158
+ Expr check , SsaDefinition def , StackVariable v , FunctionCall use , Expr usePath , Expr checkPath
159
+ ) {
160
+ checkUse ( check , checkPath , use , usePath ) and
161
+ def .getAUse ( v ) = usePath
138
162
}
139
163
140
- from Expr check , Expr checkPath , FunctionCall use , Expr usePath
164
+ from Expr check , Expr checkPath , FunctionCall use , Expr usePath , SsaDefinition def , StackVariable v
141
165
where
142
- checkUse ( check , checkPath , use , usePath ) and
143
166
// `checkPath` and `usePath` refer to the same SSA variable
144
- exists ( SsaDefinition def , StackVariable v |
145
- getACheckedPath ( check , def , v ) = checkPath and
146
- getAUsedPath ( use , def , v ) = usePath
147
- ) and
148
- // the return value of `check` is used (possibly with one step of
149
- // variable indirection) in a guard which controls `use`
150
- exists ( GuardCondition guard | referenceTo ( check , guard .getAChild * ( ) ) |
151
- guard .controls ( use .getBasicBlock ( ) , _)
152
- )
167
+ isCheckedPath ( check , def , v , use , usePath , checkPath ) and
168
+ isUsedPath ( check , def , v , use , usePath , checkPath )
153
169
select use ,
154
170
"The $@ being operated upon was previously $@, but the underlying file may have been changed since then." ,
155
171
usePath , "filename" , check , "checked"
0 commit comments