Add tests for interface embedding interface

This commit is contained in:
Owen Mansel-Chan
2024-09-24 07:31:14 +01:00
parent 279800ea62
commit 5490f3a957
22 changed files with 217 additions and 15 deletions

View File

@@ -0,0 +1,46 @@
invalidModelRow
paths
| test.go:8:7:8:16 | call to Source | test.go:10:9:10:9 | y |
| test.go:14:7:14:16 | call to Source | test.go:16:9:16:9 | y |
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y |
| test.go:26:7:26:16 | call to Source | test.go:28:9:28:9 | y |
| test.go:32:7:32:16 | call to Source | test.go:34:9:34:9 | y |
| test.go:38:7:38:16 | call to Source | test.go:40:9:40:9 | y |
| test.go:44:7:44:16 | call to Source | test.go:46:9:46:9 | y |
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
| test.go:56:7:56:16 | call to Source | test.go:58:9:58:9 | y |
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:80:7:80:16 | call to Source | test.go:82:9:82:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:14:7:14:16 | call to Source |
| test.go:20:7:20:16 | call to Source |
| test.go:26:7:26:16 | call to Source |
| test.go:32:7:32:16 | call to Source |
| test.go:38:7:38:16 | call to Source |
| test.go:44:7:44:16 | call to Source |
| test.go:50:7:50:16 | call to Source |
| test.go:56:7:56:16 | call to Source |
| test.go:62:7:62:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:80:7:80:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:16:9:16:9 | y |
| test.go:22:9:22:9 | y |
| test.go:28:9:28:9 | y |
| test.go:34:9:34:9 | y |
| test.go:40:9:40:9 | y |
| test.go:46:9:46:9 | y |
| test.go:52:9:52:9 | y |
| test.go:58:9:58:9 | y |
| test.go:64:9:64:9 | y |
| test.go:70:9:70:9 | y |
| test.go:76:9:76:9 | y |
| test.go:82:9:82:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -0,0 +1,16 @@
extensions:
- addsTo:
pack: codeql/go-all
extensible: sourceModel
data:
- ["github.com/nonexistent/test", "IEmbedI1", True, "Source", "", "", "ReturnValue", "remote", "manual"]
- addsTo:
pack: codeql/go-all
extensible: summaryModel
data:
- ["github.com/nonexistent/test", "IEmbedI1", True, "Step", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
- addsTo:
pack: codeql/go-all
extensible: sinkModel
data:
- ["github.com/nonexistent/test", "IEmbedI1", True, "Sink", "", "", "Argument[0]", "path-injection", "manual"]

View File

@@ -0,0 +1,18 @@
import go
import semmle.go.dataflow.ExternalFlow
import ModelValidation
import semmle.go.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
module Config implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { sources(source) }
predicate isSink(DataFlow::Node sink) { sinks(sink) }
}
module Flow = DataFlow::Global<Config>;
query predicate paths(DataFlow::Node source, DataFlow::Node sink) { Flow::flow(source, sink) }
query predicate sources(DataFlow::Node source) { source instanceof RemoteFlowSource }
query predicate sinks(DataFlow::Node sink) { sink = any(FileSystemAccess fsa).getAPathArgument() }

View File

@@ -0,0 +1,25 @@
invalidModelRow
paths
| test.go:14:7:14:16 | call to Source | test.go:16:9:16:9 | y |
| test.go:26:7:26:16 | call to Source | test.go:28:9:28:9 | y |
| test.go:38:7:38:16 | call to Source | test.go:40:9:40:9 | y |
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:14:7:14:16 | call to Source |
| test.go:26:7:26:16 | call to Source |
| test.go:38:7:38:16 | call to Source |
| test.go:50:7:50:16 | call to Source |
| test.go:62:7:62:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:16:9:16:9 | y |
| test.go:28:9:28:9 | y |
| test.go:40:9:40:9 | y |
| test.go:52:9:52:9 | y |
| test.go:64:9:64:9 | y |
| test.go:76:9:76:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -0,0 +1,16 @@
extensions:
- addsTo:
pack: codeql/go-all
extensible: sourceModel
data:
- ["github.com/nonexistent/test", "IEmbedI2", True, "Source", "", "", "ReturnValue", "remote", "manual"]
- addsTo:
pack: codeql/go-all
extensible: summaryModel
data:
- ["github.com/nonexistent/test", "IEmbedI2", True, "Step", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
- addsTo:
pack: codeql/go-all
extensible: sinkModel
data:
- ["github.com/nonexistent/test", "IEmbedI2", True, "Sink", "", "", "Argument[0]", "path-injection", "manual"]

View File

@@ -0,0 +1,18 @@
import go
import semmle.go.dataflow.ExternalFlow
import ModelValidation
import semmle.go.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
module Config implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node source) { sources(source) }
predicate isSink(DataFlow::Node sink) { sinks(sink) }
}
module Flow = DataFlow::Global<Config>;
query predicate paths(DataFlow::Node source, DataFlow::Node sink) { Flow::flow(source, sink) }
query predicate sources(DataFlow::Node source) { source instanceof RemoteFlowSource }
query predicate sinks(DataFlow::Node sink) { sink = any(FileSystemAccess fsa).getAPathArgument() }

View File

@@ -12,6 +12,8 @@ paths
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:80:7:80:16 | call to Source | test.go:82:9:82:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:14:7:14:16 | call to Source |
@@ -25,6 +27,8 @@ sources
| test.go:62:7:62:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:80:7:80:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:16:9:16:9 | y |
@@ -38,3 +42,5 @@ sinks
| test.go:64:9:64:9 | y |
| test.go:70:9:70:9 | y |
| test.go:76:9:76:9 | y |
| test.go:82:9:82:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -6,6 +6,7 @@ paths
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:14:7:14:16 | call to Source |
| test.go:26:7:26:16 | call to Source |
@@ -13,6 +14,7 @@ sources
| test.go:50:7:50:16 | call to Source |
| test.go:62:7:62:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:16:9:16:9 | y |
| test.go:28:9:28:9 | y |
@@ -20,3 +22,4 @@ sinks
| test.go:52:9:52:9 | y |
| test.go:64:9:64:9 | y |
| test.go:76:9:76:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -12,6 +12,8 @@ paths
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:80:7:80:16 | call to Source | test.go:82:9:82:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:14:7:14:16 | call to Source |
@@ -25,6 +27,8 @@ sources
| test.go:62:7:62:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:80:7:80:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:16:9:16:9 | y |
@@ -38,3 +42,5 @@ sinks
| test.go:64:9:64:9 | y |
| test.go:70:9:70:9 | y |
| test.go:76:9:76:9 | y |
| test.go:82:9:82:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -6,6 +6,7 @@ paths
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:14:7:14:16 | call to Source |
| test.go:26:7:26:16 | call to Source |
@@ -13,6 +14,7 @@ sources
| test.go:50:7:50:16 | call to Source |
| test.go:62:7:62:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:16:9:16:9 | y |
| test.go:28:9:28:9 | y |
@@ -20,3 +22,4 @@ sinks
| test.go:52:9:52:9 | y |
| test.go:64:9:64:9 | y |
| test.go:76:9:76:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -1,7 +1,7 @@
invalidModelRow
paths
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
| test.go:80:7:80:16 | call to Source | test.go:82:9:82:9 | y |
sources
| test.go:68:7:68:16 | call to Source |
| test.go:80:7:80:16 | call to Source |
sinks
| test.go:70:9:70:9 | y |
| test.go:82:9:82:9 | y |

View File

@@ -1,7 +1,7 @@
invalidModelRow
paths
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:74:7:74:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:76:9:76:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -2,9 +2,12 @@ invalidModelRow
paths
| test.go:8:7:8:16 | call to Source | test.go:10:9:10:9 | y |
| test.go:32:7:32:16 | call to Source | test.go:34:9:34:9 | y |
| test.go:44:7:44:16 | call to Source | test.go:46:9:46:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:32:7:32:16 | call to Source |
| test.go:44:7:44:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:34:9:34:9 | y |
| test.go:46:9:46:9 | y |

View File

@@ -12,6 +12,8 @@ paths
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:80:7:80:16 | call to Source | test.go:82:9:82:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:14:7:14:16 | call to Source |
@@ -25,6 +27,8 @@ sources
| test.go:62:7:62:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:80:7:80:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:16:9:16:9 | y |
@@ -38,3 +42,5 @@ sinks
| test.go:64:9:64:9 | y |
| test.go:70:9:70:9 | y |
| test.go:76:9:76:9 | y |
| test.go:82:9:82:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -2,9 +2,12 @@ invalidModelRow
paths
| test.go:14:7:14:16 | call to Source | test.go:16:9:16:9 | y |
| test.go:38:7:38:16 | call to Source | test.go:40:9:40:9 | y |
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
sources
| test.go:14:7:14:16 | call to Source |
| test.go:38:7:38:16 | call to Source |
| test.go:50:7:50:16 | call to Source |
sinks
| test.go:16:9:16:9 | y |
| test.go:40:9:40:9 | y |
| test.go:52:9:52:9 | y |

View File

@@ -6,6 +6,7 @@ paths
| test.go:50:7:50:16 | call to Source | test.go:52:9:52:9 | y |
| test.go:62:7:62:16 | call to Source | test.go:64:9:64:9 | y |
| test.go:74:7:74:16 | call to Source | test.go:76:9:76:9 | y |
| test.go:86:7:86:16 | call to Source | test.go:88:9:88:9 | y |
sources
| test.go:14:7:14:16 | call to Source |
| test.go:26:7:26:16 | call to Source |
@@ -13,6 +14,7 @@ sources
| test.go:50:7:50:16 | call to Source |
| test.go:62:7:62:16 | call to Source |
| test.go:74:7:74:16 | call to Source |
| test.go:86:7:86:16 | call to Source |
sinks
| test.go:16:9:16:9 | y |
| test.go:28:9:28:9 | y |
@@ -20,3 +22,4 @@ sinks
| test.go:52:9:52:9 | y |
| test.go:64:9:64:9 | y |
| test.go:76:9:76:9 | y |
| test.go:88:9:88:9 | y |

View File

@@ -1,10 +1,10 @@
invalidModelRow
paths
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y |
| test.go:56:7:56:16 | call to Source | test.go:58:9:58:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
sources
| test.go:20:7:20:16 | call to Source |
| test.go:56:7:56:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
sinks
| test.go:22:9:22:9 | y |
| test.go:58:9:58:9 | y |
| test.go:70:9:70:9 | y |

View File

@@ -1,10 +1,10 @@
invalidModelRow
paths
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y |
| test.go:56:7:56:16 | call to Source | test.go:58:9:58:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
sources
| test.go:20:7:20:16 | call to Source |
| test.go:56:7:56:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
sinks
| test.go:22:9:22:9 | y |
| test.go:58:9:58:9 | y |
| test.go:70:9:70:9 | y |

View File

@@ -2,9 +2,12 @@ invalidModelRow
paths
| test.go:8:7:8:16 | call to Source | test.go:10:9:10:9 | y |
| test.go:32:7:32:16 | call to Source | test.go:34:9:34:9 | y |
| test.go:44:7:44:16 | call to Source | test.go:46:9:46:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:32:7:32:16 | call to Source |
| test.go:44:7:44:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:34:9:34:9 | y |
| test.go:46:9:46:9 | y |

View File

@@ -3,14 +3,17 @@ paths
| test.go:8:7:8:16 | call to Source | test.go:10:9:10:9 | y |
| test.go:20:7:20:16 | call to Source | test.go:22:9:22:9 | y |
| test.go:32:7:32:16 | call to Source | test.go:34:9:34:9 | y |
| test.go:56:7:56:16 | call to Source | test.go:58:9:58:9 | y |
| test.go:44:7:44:16 | call to Source | test.go:46:9:46:9 | y |
| test.go:68:7:68:16 | call to Source | test.go:70:9:70:9 | y |
sources
| test.go:8:7:8:16 | call to Source |
| test.go:20:7:20:16 | call to Source |
| test.go:32:7:32:16 | call to Source |
| test.go:56:7:56:16 | call to Source |
| test.go:44:7:44:16 | call to Source |
| test.go:68:7:68:16 | call to Source |
sinks
| test.go:10:9:10:9 | y |
| test.go:22:9:22:9 | y |
| test.go:34:9:34:9 | y |
| test.go:58:9:58:9 | y |
| test.go:46:9:46:9 | y |
| test.go:70:9:70:9 | y |

View File

@@ -40,6 +40,18 @@ func TestSEmbedI2(t test.SEmbedI2) {
t.Sink(y)
}
func TestIEmbedI1(t test.IEmbedI1) {
x := t.Source()
y := t.Step(x)
t.Sink(y)
}
func TestIEmbedI2(t test.IEmbedI2) {
x := t.Source()
y := t.Step(x)
t.Sink(y)
}
func TestSImplEmbedI1(t test.SImplEmbedI1) {
x := t.Source()
y := t.Step(x)

View File

@@ -49,6 +49,18 @@ type SEmbedI1 struct{ I1 }
// A struct type embedding I2
type SEmbedI2 struct{ I2 }
// An interface type embedding I1
type IEmbedI1 interface {
I1
ExtraMethodIEmbedI1()
}
// An interface type embedding I2
type IEmbedI2 interface {
I2
ExtraMethodIEmbedI2()
}
// A struct type embedding I1 and separately implementing its methods, so the
// methods of the embedded field are not promoted.
type SImplEmbedI1 struct{ I1 }