@@ -143,102 +143,55 @@ predicate jumpStep(Node n1, Node n2) {
143143 * Thus, `node2` references an object with a content `x` that contains the
144144 * value of `node1`.
145145 */
146- predicate storeStep ( Node node1 , ContentSet c , Node node2 ) {
147- // a write `(*p).f = rhs` is modeled as two store steps: `rhs` is flows into field `f` of `(*p)`,
148- // which in turn flows into the pointer content of `p`
149- exists ( Write w , Field f , DataFlow:: Node base , DataFlow:: Node rhs | w .writesField ( base , f , rhs ) |
150- node1 = rhs and
151- node2 .( PostUpdateNode ) .getPreUpdateNode ( ) = base and
152- c = any ( DataFlow:: FieldContent fc | fc .getField ( ) = f )
146+ predicate storeStep ( Node node1 , ContentSet cs , Node node2 ) {
147+ exists ( Content c | cs .asOneContent ( ) = c |
148+ // a write `(*p).f = rhs` is modeled as two store steps: `rhs` is flows into field `f` of `(*p)`,
149+ // which in turn flows into the pointer content of `p`
150+ exists ( Write w , Field f , DataFlow:: Node base , DataFlow:: Node rhs | w .writesField ( base , f , rhs ) |
151+ node1 = rhs and
152+ node2 .( PostUpdateNode ) .getPreUpdateNode ( ) = base and
153+ c = any ( DataFlow:: FieldContent fc | fc .getField ( ) = f )
154+ or
155+ node1 = base and
156+ node2 .( PostUpdateNode ) .getPreUpdateNode ( ) = node1 .( PointerDereferenceNode ) .getOperand ( ) and
157+ c = any ( DataFlow:: PointerContent pc | pc .getPointerType ( ) = node2 .getType ( ) )
158+ )
153159 or
154- node1 = base and
155- node2 .( PostUpdateNode ) .getPreUpdateNode ( ) = node1 .( PointerDereferenceNode ) .getOperand ( ) and
160+ node1 = node2 .( AddressOperationNode ) .getOperand ( ) and
156161 c = any ( DataFlow:: PointerContent pc | pc .getPointerType ( ) = node2 .getType ( ) )
162+ or
163+ containerStoreStep ( node1 , node2 , c )
157164 )
158165 or
159- node1 = node2 .( AddressOperationNode ) .getOperand ( ) and
160- c = any ( DataFlow:: PointerContent pc | pc .getPointerType ( ) = node2 .getType ( ) )
161- or
162- FlowSummaryImpl:: Private:: Steps:: summaryStoreStep ( node1 .( FlowSummaryNode ) .getSummaryNode ( ) , c ,
166+ FlowSummaryImpl:: Private:: Steps:: summaryStoreStep ( node1 .( FlowSummaryNode ) .getSummaryNode ( ) , cs ,
163167 node2 .( FlowSummaryNode ) .getSummaryNode ( ) )
164- or
165- containerStoreStep ( node1 , node2 , c )
166- }
167-
168- /**
169- * Gets a `DataFlow::ContentSet` containing a single `Content` appropriate
170- * for reading a field, element, map value or channel message of type `containerType`.
171- */
172- DataFlow:: ContentSet getContentForType ( Type containerType ) {
173- containerType instanceof ArrayType and
174- result instanceof DataFlow:: ArrayContent
175- or
176- containerType instanceof SliceType and
177- result instanceof DataFlow:: ArrayContent
178- or
179- containerType instanceof ChanType and
180- result instanceof DataFlow:: CollectionContent
181- or
182- containerType instanceof MapType and
183- result instanceof DataFlow:: MapValueContent
184- or
185- result .( DataFlow:: PointerContent ) .getPointerType ( ) = containerType
186- or
187- exists ( Field f | f = containerType .( StructType ) .getField ( _) |
188- result .( DataFlow:: FieldContent ) .getField ( ) = f
189- )
190- }
191-
192- /**
193- * Gets the type of an array/slice element, channel value, map value,
194- * pointer base type or named-type underlying type relating to `containerType`.
195- */
196- Type getElementType ( Type containerType ) {
197- result = containerType .( ArrayType ) .getElementType ( ) or
198- result = containerType .( SliceType ) .getElementType ( ) or
199- result = containerType .( ChanType ) .getElementType ( ) or
200- result = containerType .( MapType ) .getValueType ( ) or
201- result = containerType .( PointerType ) .getPointerType ( ) or
202- result = containerType .( NamedType ) .getUnderlyingType ( )
203- }
204-
205- /**
206- * Gets the type of an array/slice element, channel value, map value,
207- * pointer base type, named-type underlying type or struct field type
208- * relating to `containerType`.
209- */
210- Type getAnElementOrFieldType ( Type containerType ) {
211- result = getElementType ( containerType ) or
212- result = containerType .( StructType ) .getField ( _) .getType ( )
213168}
214169
215170/**
216171 * Holds if data can flow from `node1` to `node2` via a read of `c`.
217172 * Thus, `node1` references an object with a content `c` whose value ends up in
218173 * `node2`.
219174 */
220- predicate readStep ( Node node1 , ContentSet c , Node node2 ) {
221- node1 = node2 .( PointerDereferenceNode ) .getOperand ( ) and
222- c = any ( DataFlow:: PointerContent pc | pc .getPointerType ( ) = node1 .getType ( ) )
223- or
224- exists ( FieldReadNode read |
225- node2 = read and
226- node1 = read .getBase ( ) and
227- c = any ( DataFlow:: FieldContent fc | fc .getField ( ) = read .getField ( ) )
175+ predicate readStep ( Node node1 , ContentSet cs , Node node2 ) {
176+ exists ( Content c | cs .asOneContent ( ) = c |
177+ node1 = node2 .( PointerDereferenceNode ) .getOperand ( ) and
178+ c = any ( DataFlow:: PointerContent pc | pc .getPointerType ( ) = node1 .getType ( ) )
179+ or
180+ exists ( FieldReadNode read |
181+ node2 = read and
182+ node1 = read .getBase ( ) and
183+ c = any ( DataFlow:: FieldContent fc | fc .getField ( ) = read .getField ( ) )
184+ )
185+ or
186+ containerReadStep ( node1 , node2 , c )
228187 )
229188 or
230- FlowSummaryImpl:: Private:: Steps:: summaryReadStep ( node1 .( FlowSummaryNode ) .getSummaryNode ( ) , c ,
189+ FlowSummaryImpl:: Private:: Steps:: summaryReadStep ( node1 .( FlowSummaryNode ) .getSummaryNode ( ) , cs ,
231190 node2 .( FlowSummaryNode ) .getSummaryNode ( ) )
232191 or
233- containerReadStep ( node1 , node2 , c )
234- or
235- exists ( Type containerType |
236- any ( ImplicitFieldReadNode ifrn ) .shouldImplicitlyReadAllFields ( node1 ) and
237- getAnElementOrFieldType * ( node1 .getType ( ) ) = containerType
238- |
239- c = getContentForType ( containerType ) and
240- node1 = node2
241- )
192+ any ( ImplicitFieldReadNode ifrn ) .shouldImplicitlyReadAllFields ( node1 ) and
193+ cs .isUniversalContent ( ) and
194+ node1 = node2
242195}
243196
244197/**
0 commit comments