Skip to content

Commit df7a54b

Browse files
committed
Be more careful about type equivalence up to aliasing in read steps
1 parent 727c19c commit df7a54b

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

go/ql/lib/semmle/go/dataflow/internal/ContainerFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ predicate containerStoreStep(Node node1, Node node2, Content c) {
5757
* as well as array iteration through enhanced `for` statements.
5858
*/
5959
predicate containerReadStep(Node node1, Node node2, Content c) {
60-
exists(Type t | t = node1.getType().getUnderlyingType() |
60+
exists(Type t | t = node1.getType().getUnderlyingType().getDeepUnaliasedType() |
6161
c instanceof ArrayContent and
6262
(
6363
t instanceof ArrayType or

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,21 @@ predicate readStep(Node node1, ContentSet cs, Node node2) {
180180
exists(Content c | cs.asOneContent() = c |
181181
node1 = node2.(PointerDereferenceNode).getOperand() and
182182
c =
183-
any(DataFlow::PointerContent pc | pc.getPointerType() = node1.getType().getDeepUnaliasedType())
183+
any(DataFlow::PointerContent pc |
184+
pc.getPointerType().getDeepUnaliasedType() = node1.getType().getDeepUnaliasedType()
185+
)
184186
or
185187
exists(FieldReadNode read |
186188
node2 = read and
187189
node1 = read.getBase() and
188-
c = any(DataFlow::FieldContent fc | fc.getField() = read.getField())
190+
exists(DataFlow::FieldContent fc, Field f1, Field f2 |
191+
f1 = fc.getField() and
192+
f2 = read.getField() and
193+
f1.getDeclaringType().getDeepUnaliasedType() = f2.getDeclaringType().getDeepUnaliasedType() and
194+
f1.getName() = f2.getName()
195+
|
196+
c = fc
197+
)
189198
)
190199
or
191200
containerReadStep(node1, node2, c)

go/ql/lib/semmle/go/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ predicate localTaintStep(DataFlow::Node src, DataFlow::Node sink) {
3535
}
3636

3737
private Type getElementType(Type containerType) {
38-
result = containerType.(ArrayType).getElementType() or
39-
result = containerType.(SliceType).getElementType() or
40-
result = containerType.(ChanType).getElementType() or
41-
result = containerType.(MapType).getValueType() or
42-
result = containerType.(PointerType).getPointerType()
38+
result = containerType.getDeepUnaliasedType().(ArrayType).getElementType() or
39+
result = containerType.getDeepUnaliasedType().(SliceType).getElementType() or
40+
result = containerType.getDeepUnaliasedType().(ChanType).getElementType() or
41+
result = containerType.getDeepUnaliasedType().(MapType).getValueType() or
42+
result = containerType.getDeepUnaliasedType().(PointerType).getPointerType()
4343
}
4444

4545
/**
@@ -50,7 +50,7 @@ bindingset[node]
5050
predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet cs) {
5151
exists(Type containerType, DataFlow::Content c |
5252
node instanceof DataFlow::ArgumentNode and
53-
getElementType*(node.getType()) = containerType and
53+
getElementType*(node.getType()).getDeepUnaliasedType() = containerType and
5454
cs.asOneContent() = c
5555
|
5656
containerType instanceof ArrayType and
@@ -65,7 +65,7 @@ predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet cs)
6565
containerType instanceof MapType and
6666
c instanceof DataFlow::MapValueContent
6767
or
68-
c.(DataFlow::PointerContent).getPointerType() = containerType
68+
c.(DataFlow::PointerContent).getPointerType().getDeepUnaliasedType() = containerType
6969
)
7070
}
7171

0 commit comments

Comments
 (0)