|
1 | 1 | private import java |
2 | 2 | private import semmle.code.java.dataflow.InstanceAccess |
| 3 | +private import semmle.code.java.dataflow.ExternalFlow |
3 | 4 | private import semmle.code.java.dataflow.FlowSummary |
4 | 5 | private import semmle.code.java.dataflow.TypeFlow |
5 | 6 | private import DataFlowPrivate |
| 7 | +private import DataFlowUtil |
6 | 8 | private import FlowSummaryImpl as FlowSummaryImpl |
7 | 9 | private import DataFlowImplCommon as DataFlowImplCommon |
8 | 10 |
|
| 11 | +/** Gets a string for approximating the name of a field. */ |
| 12 | +string approximateFieldContent(FieldContent fc) { result = fc.getField().getName().prefix(1) } |
| 13 | + |
9 | 14 | cached |
10 | | -newtype TNode = |
11 | | - TExprNode(Expr e) { |
12 | | - DataFlowImplCommon::forceCachingInSameStage() and |
13 | | - not e.getType() instanceof VoidType and |
14 | | - not e.getParent*() instanceof Annotation |
15 | | - } or |
16 | | - TExplicitParameterNode(Parameter p) { exists(p.getCallable().getBody()) } or |
17 | | - TImplicitVarargsArray(Call c) { |
18 | | - c.getCallee().isVarargs() and |
19 | | - not exists(Argument arg | arg.getCall() = c and arg.isExplicitVarargsArray()) |
20 | | - } or |
21 | | - TInstanceParameterNode(Callable c) { exists(c.getBody()) and not c.isStatic() } or |
22 | | - TImplicitInstanceAccess(InstanceAccessExt ia) { not ia.isExplicit(_) } or |
23 | | - TMallocNode(ClassInstanceExpr cie) or |
24 | | - TExplicitExprPostUpdate(Expr e) { |
25 | | - explicitInstanceArgument(_, e) |
26 | | - or |
27 | | - e instanceof Argument and not e.getType() instanceof ImmutableType |
28 | | - or |
29 | | - exists(FieldAccess fa | fa.getField() instanceof InstanceField and e = fa.getQualifier()) |
30 | | - or |
31 | | - exists(ArrayAccess aa | e = aa.getArray()) |
32 | | - } or |
33 | | - TImplicitExprPostUpdate(InstanceAccessExt ia) { |
34 | | - implicitInstanceArgument(_, ia) |
35 | | - or |
36 | | - exists(FieldAccess fa | |
37 | | - fa.getField() instanceof InstanceField and ia.isImplicitFieldQualifier(fa) |
38 | | - ) |
39 | | - } or |
40 | | - TSummaryInternalNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) { |
41 | | - FlowSummaryImpl::Private::summaryNodeRange(c, state) |
42 | | - } or |
43 | | - TSummaryParameterNode(SummarizedCallable c, int pos) { |
44 | | - FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos) |
45 | | - } or |
46 | | - TFieldValueNode(Field f) |
| 15 | +private module Cached { |
| 16 | + cached |
| 17 | + newtype TNode = |
| 18 | + TExprNode(Expr e) { |
| 19 | + DataFlowImplCommon::forceCachingInSameStage() and |
| 20 | + not e.getType() instanceof VoidType and |
| 21 | + not e.getParent*() instanceof Annotation |
| 22 | + } or |
| 23 | + TExplicitParameterNode(Parameter p) { exists(p.getCallable().getBody()) } or |
| 24 | + TImplicitVarargsArray(Call c) { |
| 25 | + c.getCallee().isVarargs() and |
| 26 | + not exists(Argument arg | arg.getCall() = c and arg.isExplicitVarargsArray()) |
| 27 | + } or |
| 28 | + TInstanceParameterNode(Callable c) { exists(c.getBody()) and not c.isStatic() } or |
| 29 | + TImplicitInstanceAccess(InstanceAccessExt ia) { not ia.isExplicit(_) } or |
| 30 | + TMallocNode(ClassInstanceExpr cie) or |
| 31 | + TExplicitExprPostUpdate(Expr e) { |
| 32 | + explicitInstanceArgument(_, e) |
| 33 | + or |
| 34 | + e instanceof Argument and not e.getType() instanceof ImmutableType |
| 35 | + or |
| 36 | + exists(FieldAccess fa | fa.getField() instanceof InstanceField and e = fa.getQualifier()) |
| 37 | + or |
| 38 | + exists(ArrayAccess aa | e = aa.getArray()) |
| 39 | + } or |
| 40 | + TImplicitExprPostUpdate(InstanceAccessExt ia) { |
| 41 | + implicitInstanceArgument(_, ia) |
| 42 | + or |
| 43 | + exists(FieldAccess fa | |
| 44 | + fa.getField() instanceof InstanceField and ia.isImplicitFieldQualifier(fa) |
| 45 | + ) |
| 46 | + } or |
| 47 | + TSummaryInternalNode(SummarizedCallable c, FlowSummaryImpl::Private::SummaryNodeState state) { |
| 48 | + FlowSummaryImpl::Private::summaryNodeRange(c, state) |
| 49 | + } or |
| 50 | + TSummaryParameterNode(SummarizedCallable c, int pos) { |
| 51 | + FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos) |
| 52 | + } or |
| 53 | + TFieldValueNode(Field f) |
| 54 | + |
| 55 | + cached |
| 56 | + newtype TContent = |
| 57 | + TFieldContent(InstanceField f) or |
| 58 | + TArrayContent() or |
| 59 | + TCollectionContent() or |
| 60 | + TMapKeyContent() or |
| 61 | + TMapValueContent() or |
| 62 | + TSyntheticFieldContent(SyntheticField s) |
| 63 | + |
| 64 | + cached |
| 65 | + newtype TContentApprox = |
| 66 | + TFieldContentApprox(string firstChar) { firstChar = approximateFieldContent(_) } or |
| 67 | + TArrayContentApprox() or |
| 68 | + TCollectionContentApprox() or |
| 69 | + TMapKeyContentApprox() or |
| 70 | + TMapValueContentApprox() or |
| 71 | + TSyntheticFieldApproxContent() |
| 72 | +} |
| 73 | + |
| 74 | +import Cached |
47 | 75 |
|
48 | 76 | private predicate explicitInstanceArgument(Call call, Expr instarg) { |
49 | 77 | call instanceof MethodAccess and |
|
0 commit comments