1010 */
1111
1212import MemoryFreed
13- import semmle.code.cpp.controlflow.LocalScopeVariableReachability
13+ import semmle.code.cpp.controlflow.StackVariableReachability
1414
1515/**
1616 * 'call' is either a direct call to f, or a possible call to f
@@ -97,18 +97,18 @@ predicate freeCallOrIndirect(ControlFlowNode n, Variable v) {
9797 )
9898}
9999
100- predicate allocationDefinition ( LocalScopeVariable v , ControlFlowNode def ) {
100+ predicate allocationDefinition ( StackVariable v , ControlFlowNode def ) {
101101 exists ( Expr expr | exprDefinition ( v , def , expr ) and allocCallOrIndirect ( expr ) )
102102}
103103
104- class AllocVariableReachability extends LocalScopeVariableReachabilityWithReassignment {
104+ class AllocVariableReachability extends StackVariableReachabilityWithReassignment {
105105 AllocVariableReachability ( ) { this = "AllocVariableReachability" }
106106
107- override predicate isSourceActual ( ControlFlowNode node , LocalScopeVariable v ) {
107+ override predicate isSourceActual ( ControlFlowNode node , StackVariable v ) {
108108 allocationDefinition ( v , node )
109109 }
110110
111- override predicate isSinkActual ( ControlFlowNode node , LocalScopeVariable v ) {
111+ override predicate isSinkActual ( ControlFlowNode node , StackVariable v ) {
112112 // node may be used in allocationReaches
113113 exists ( node .( AnalysedExpr ) .getNullSuccessor ( v ) ) or
114114 freeCallOrIndirect ( node , v ) or
@@ -117,15 +117,13 @@ class AllocVariableReachability extends LocalScopeVariableReachabilityWithReassi
117117 v .getFunction ( ) = node .( ReturnStmt ) .getEnclosingFunction ( )
118118 }
119119
120- override predicate isBarrier ( ControlFlowNode node , LocalScopeVariable v ) {
121- definitionBarrier ( v , node )
122- }
120+ override predicate isBarrier ( ControlFlowNode node , StackVariable v ) { definitionBarrier ( v , node ) }
123121}
124122
125123/**
126124 * The value from allocation `def` is still held in Variable `v` upon entering `node`.
127125 */
128- predicate allocatedVariableReaches ( LocalScopeVariable v , ControlFlowNode def , ControlFlowNode node ) {
126+ predicate allocatedVariableReaches ( StackVariable v , ControlFlowNode def , ControlFlowNode node ) {
129127 exists ( AllocVariableReachability r |
130128 // reachability
131129 r .reachesTo ( def , _, node , v )
@@ -136,25 +134,25 @@ predicate allocatedVariableReaches(LocalScopeVariable v, ControlFlowNode def, Co
136134 )
137135}
138136
139- class AllocReachability extends LocalScopeVariableReachabilityExt {
137+ class AllocReachability extends StackVariableReachabilityExt {
140138 AllocReachability ( ) { this = "AllocReachability" }
141139
142- override predicate isSource ( ControlFlowNode node , LocalScopeVariable v ) {
140+ override predicate isSource ( ControlFlowNode node , StackVariable v ) {
143141 allocationDefinition ( v , node )
144142 }
145143
146- override predicate isSink ( ControlFlowNode node , LocalScopeVariable v ) {
144+ override predicate isSink ( ControlFlowNode node , StackVariable v ) {
147145 v .getFunction ( ) = node .( ReturnStmt ) .getEnclosingFunction ( )
148146 }
149147
150148 override predicate isBarrier (
151- ControlFlowNode source , ControlFlowNode node , ControlFlowNode next , LocalScopeVariable v
149+ ControlFlowNode source , ControlFlowNode node , ControlFlowNode next , StackVariable v
152150 ) {
153151 isSource ( source , v ) and
154152 next = node .getASuccessor ( ) and
155153 // the memory (stored in any variable `v0`) allocated at `source` is freed or
156154 // assigned to a global at node, or NULL checked on the edge node -> next.
157- exists ( LocalScopeVariable v0 | allocatedVariableReaches ( v0 , source , node ) |
155+ exists ( StackVariable v0 | allocatedVariableReaches ( v0 , source , node ) |
158156 node .( AnalysedExpr ) .getNullSuccessor ( v0 ) = next or
159157 freeCallOrIndirect ( node , v0 ) or
160158 assignedToFieldOrGlobal ( v0 , node )
@@ -171,11 +169,11 @@ predicate allocationReaches(ControlFlowNode def, ControlFlowNode node) {
171169 exists ( AllocReachability r | r .reaches ( def , _, node ) )
172170}
173171
174- predicate assignedToFieldOrGlobal ( LocalScopeVariable v , Expr e ) {
175- // assigned to anything except a LocalScopeVariable
172+ predicate assignedToFieldOrGlobal ( StackVariable v , Expr e ) {
173+ // assigned to anything except a StackVariable
176174 // (typically a field or global, but for example also *ptr = v)
177175 e .( Assignment ) .getRValue ( ) = v .getAnAccess ( ) and
178- not e .( Assignment ) .getLValue ( ) .( VariableAccess ) .getTarget ( ) instanceof LocalScopeVariable
176+ not e .( Assignment ) .getLValue ( ) .( VariableAccess ) .getTarget ( ) instanceof StackVariable
179177 or
180178 exists ( Expr midExpr , Function mid , int arg |
181179 // indirect assignment
@@ -192,7 +190,7 @@ predicate assignedToFieldOrGlobal(LocalScopeVariable v, Expr e) {
192190from ControlFlowNode def , ReturnStmt ret
193191where
194192 allocationReaches ( def , ret ) and
195- not exists ( LocalScopeVariable v |
193+ not exists ( StackVariable v |
196194 allocatedVariableReaches ( v , def , ret ) and
197195 ret .getAChild * ( ) = v .getAnAccess ( )
198196 )
0 commit comments