Skip to content

Commit 99c9914

Browse files
author
Max Schaefer
committed
Rename {source,sink}Model to {source,sink}ModelCandidate.
1 parent a3816d7 commit 99c9914

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

java/ql/automodel/test/AutomodelApplicationModeExtraction/PluginImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class PluginImpl extends Plugin {
44
@Override
5-
public void configure(String name, String value) { // $ sourceModel=configure(String,String):Parameter[0] sourceModel=configure(String,String):Parameter[1]
5+
public void configure(String name, String value) { // $ sourceModelCandidate=configure(String,String):Parameter[0] sourceModelCandidate=configure(String,String):Parameter[1]
66
// ...
77
}
88
}

java/ql/automodel/test/AutomodelApplicationModeExtraction/Test.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@
1616
class Test {
1717
public static void main(String[] args) throws Exception {
1818
AtomicReference<String> reference = new AtomicReference<>(); // uninteresting (parameterless constructor)
19-
reference.set( // $ sinkModel=set(Object):Argument[this]
19+
reference.set( // $ sinkModelCandidate=set(Object):Argument[this]
2020
args[0] // $ negativeSinkExample=set(Object):Argument[0] // modeled as a flow step
2121
); // $ negativeSourceExample=set(Object):ReturnValue // return type is void
2222
}
2323

2424
public static void callSupplier(Supplier<String> supplier) {
25-
supplier.get(); // $ sourceModel=get():ReturnValue sinkModel=get():Argument[this]
25+
supplier.get(); // $ sourceModelCandidate=get():ReturnValue sinkModelCandidate=get():Argument[this]
2626
}
2727

2828
public static void copyFiles(Path source, Path target, CopyOption option) throws Exception {
2929
Files.copy(
3030
source, // $ positiveSinkExample=copy(Path,Path,CopyOption[]):Argument[0](path-injection)
3131
target, // $ positiveSinkExample=copy(Path,Path,CopyOption[]):Argument[1](path-injection)
3232
option // no candidate (not modeled, but source and target are modeled)
33-
); // $ sourceModel=copy(Path,Path,CopyOption[]):ReturnValue
33+
); // $ sourceModelCandidate=copy(Path,Path,CopyOption[]):ReturnValue
3434
}
3535

3636
public static InputStream getInputStream(Path openPath) throws Exception {
3737
return Files.newInputStream(
38-
openPath // $ sinkModel=newInputStream(Path,OpenOption[]):Argument[0] positiveSinkExample=newInputStream(Path,OpenOption[]):Argument[0](path-injection) // sink candidate because "only" ai-modeled, and useful as a candidate in regression testing
39-
); // $ sourceModel=newInputStream(Path,OpenOption[]):ReturnValue
38+
openPath // $ sinkModelCandidate=newInputStream(Path,OpenOption[]):Argument[0] positiveSinkExample=newInputStream(Path,OpenOption[]):Argument[0](path-injection) // sink candidate because "only" ai-modeled, and useful as a candidate in regression testing
39+
); // $ sourceModelCandidate=newInputStream(Path,OpenOption[]):ReturnValue
4040
}
4141

4242
public static InputStream getInputStream(String openPath) throws Exception {
4343
return Test.getInputStream( // the call is not a source candidate (argument to local call)
4444
Paths.get(
4545
openPath // $ negativeSinkExample=get(String,String[]):Argument[0] // modeled as a flow step
46-
) // $ sourceModel=get(String,String[]):ReturnValue
46+
) // $ sourceModelCandidate=get(String,String[]):ReturnValue
4747
);
4848
}
4949

@@ -59,16 +59,16 @@ public static void FilesWalkExample(Path p, FileVisitOption o) throws Exception
5959
o, // the implicit varargs array is a candidate, annotated on the last line of the call
6060
o // not a candidate (only the first arg corresponding to a varargs array
6161
// is extracted)
62-
); // $ sourceModel=walk(Path,FileVisitOption[]):ReturnValue sinkModel=walk(Path,FileVisitOption[]):Argument[1]
62+
); // $ sourceModelCandidate=walk(Path,FileVisitOption[]):ReturnValue sinkModelCandidate=walk(Path,FileVisitOption[]):Argument[1]
6363
}
6464

6565
public static void WebSocketExample(URLConnection c) throws Exception {
66-
c.getInputStream(); // $ sinkModel=getInputStream():Argument[this] positiveSourceExample=getInputStream():ReturnValue(remote) // not a source candidate (manual modeling)
66+
c.getInputStream(); // $ sinkModelCandidate=getInputStream():Argument[this] positiveSourceExample=getInputStream():ReturnValue(remote) // not a source candidate (manual modeling)
6767
}
6868
}
6969

7070
class OverrideTest extends Exception {
71-
public void printStackTrace(PrintWriter writer) { // $ sourceModel=printStackTrace(PrintWriter):Parameter[0]
71+
public void printStackTrace(PrintWriter writer) { // $ sourceModelCandidate=printStackTrace(PrintWriter):Parameter[0]
7272
return;
7373
}
7474

@@ -89,15 +89,15 @@ public static void FilesListExample(Path p) throws Exception {
8989
Files.list(
9090
Files.createDirectories(
9191
p // $ positiveSinkExample=createDirectories(Path,FileAttribute[]):Argument[0](path-injection)
92-
) // $ sourceModel=createDirectories(Path,FileAttribute[]):ReturnValue negativeSinkExample=list(Path):Argument[0] // modeled as a flow step
93-
); // $ sourceModel=list(Path):ReturnValue
92+
) // $ sourceModelCandidate=createDirectories(Path,FileAttribute[]):ReturnValue negativeSinkExample=list(Path):Argument[0] // modeled as a flow step
93+
); // $ sourceModelCandidate=list(Path):ReturnValue
9494

9595
Files.delete(
96-
p // $ sinkModel=delete(Path):Argument[0] positiveSinkExample=delete(Path):Argument[0](path-injection)
96+
p // $ sinkModelCandidate=delete(Path):Argument[0] positiveSinkExample=delete(Path):Argument[0](path-injection)
9797
); // $ negativeSourceExample=delete(Path):ReturnValue // return type is void
9898

9999
Files.deleteIfExists(
100-
p // $ sinkModel=deleteIfExists(Path):Argument[0] positiveSinkExample=deleteIfExists(Path):Argument[0](path-injection)
100+
p // $ sinkModelCandidate=deleteIfExists(Path):Argument[0] positiveSinkExample=deleteIfExists(Path):Argument[0](path-injection)
101101
); // $ negativeSourceExample=deleteIfExists(Path):ReturnValue // return type is boolean
102102
}
103103
}

java/ql/automodel/test/AutomodelExtractionTests.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ signature module TestHelperSig<CandidateSig Candidate> {
2424
module Extraction<CandidateSig Candidate, TestHelperSig<Candidate> TestHelper> implements TestSig {
2525
string getARelevantTag() {
2626
result in [
27-
"sourceModel", "sinkModel", // a candidate source/sink
27+
"sourceModelCandidate", "sinkModelCandidate", // a candidate source/sink
2828
"positiveSourceExample", "positiveSinkExample", // a known source/sink
2929
"negativeSourceExample", "negativeSinkExample" // a known non-source/non-sink
3030
]
@@ -46,7 +46,7 @@ module Extraction<CandidateSig Candidate, TestHelperSig<Candidate> TestHelper> i
4646
string extensibleType, string tag, string suffix
4747
) {
4848
TestHelper::isCandidate(endpoint, name, signature, input, output, extensibleType) and
49-
tag = extensibleType and
49+
tag = ifSource(extensibleType, "sourceModelCandidate", "sinkModelCandidate") and
5050
suffix = ""
5151
or
5252
TestHelper::isNegativeExample(endpoint, name, signature, input, output, extensibleType) and
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
package com.github.codeql.test;
22

33
public class PublicClass {
4-
public void stuff(String arg) { // $ sinkModel=stuff(String):Argument[this] sourceModel=stuff(String):Parameter[this] sinkModel=stuff(String):Argument[0] sourceModel=stuff(String):Parameter[0] // source candidates because it is an overrideable method
4+
public void stuff(String arg) { // $ sinkModelCandidate=stuff(String):Argument[this] sourceModelCandidate=stuff(String):Parameter[this] sinkModelCandidate=stuff(String):Argument[0] sourceModelCandidate=stuff(String):Parameter[0] // source candidates because it is an overrideable method
55
System.out.println(arg);
66
}
77

8-
public static void staticStuff(String arg) { // $ sinkModel=staticStuff(String):Argument[0] // `arg` is not a source candidate (not overrideabe); `this` is not a candidate (static method)
8+
public static void staticStuff(String arg) { // $ sinkModelCandidate=staticStuff(String):Argument[0] // `arg` is not a source candidate (not overrideabe); `this` is not a candidate (static method)
99
System.out.println(arg);
1010
}
1111

12-
protected void nonPublicStuff(String arg) { // $ sinkModel=nonPublicStuff(String):Argument[this] sourceModel=nonPublicStuff(String):Parameter[this] sinkModel=nonPublicStuff(String):Argument[0] sourceModel=nonPublicStuff(String):Parameter[0]
12+
protected void nonPublicStuff(String arg) { // $ sinkModelCandidate=nonPublicStuff(String):Argument[this] sourceModelCandidate=nonPublicStuff(String):Parameter[this] sinkModelCandidate=nonPublicStuff(String):Argument[0] sourceModelCandidate=nonPublicStuff(String):Parameter[0]
1313
System.out.println(arg);
1414
}
1515

1616
void packagePrivateStuff(String arg) { // no candidates because the method is not public
1717
System.out.println(arg);
1818
}
1919

20-
public PublicClass(Object input) { // $ sourceModel=PublicClass(Object):ReturnValue sinkModel=PublicClass(Object):Argument[0] // `this` is not a candidate because it is a constructor
20+
public PublicClass(Object input) { // $ sourceModelCandidate=PublicClass(Object):ReturnValue sinkModelCandidate=PublicClass(Object):Argument[0] // `this` is not a candidate because it is a constructor
2121
}
2222

2323
// `input` and `input` are source candidates, but not sink candidates (is-style method)
24-
public Boolean isIgnored(Object input) { // $ negativeSinkExample=isIgnored(Object):Argument[this] sourceModel=isIgnored(Object):Parameter[this] negativeSinkExample=isIgnored(Object):Argument[0] sourceModel=isIgnored(Object):Parameter[0]
24+
public Boolean isIgnored(Object input) { // $ negativeSinkExample=isIgnored(Object):Argument[this] sourceModelCandidate=isIgnored(Object):Parameter[this] negativeSinkExample=isIgnored(Object):Argument[0] sourceModelCandidate=isIgnored(Object):Parameter[0]
2525
return false;
2626
}
2727
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.github.codeql.test;
22

33
public interface PublicInterface {
4-
public int stuff(String arg); // $ sinkModel=stuff(String):Argument[this] sourceModel=stuff(String):Parameter[this] sinkModel=stuff(String):Argument[0] sourceModel=stuff(String):Parameter[0] // result is _not_ a source candidate source (primitive return type)
4+
public int stuff(String arg); // $ sinkModelCandidate=stuff(String):Argument[this] sourceModelCandidate=stuff(String):Parameter[this] sinkModelCandidate=stuff(String):Argument[0] sourceModelCandidate=stuff(String):Parameter[0] // result is _not_ a source candidate source (primitive return type)
55

6-
public static void staticStuff(String arg) { // $ sinkModel=staticStuff(String):Argument[0] // not a source candidate (static method)
6+
public static void staticStuff(String arg) { // $ sinkModelCandidate=staticStuff(String):Argument[0] // not a source candidate (static method)
77
System.out.println(arg);
88
}
99
}

java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/io/File.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public int compareTo( // $ negativeSinkExample=compareTo(File):Argument[this] ne
77
return 0;
88
}
99

10-
public boolean setLastModified(long time) { // $ sinkModel=setLastModified(long):Argument[this] sourceModel=setLastModified(long):Parameter[this] // time is not a candidate (primitive type)
10+
public boolean setLastModified(long time) { // $ sinkModelCandidate=setLastModified(long):Argument[this] sourceModelCandidate=setLastModified(long):Parameter[this] // time is not a candidate (primitive type)
1111
return false;
1212
} // return value is not a source candidate because it's a primitive
1313
}

java/ql/automodel/test/AutomodelFrameworkModeExtraction/java/nio/file/Files.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class Files {
1212
public static void copy( // method result is not a candidate source (void)
1313
Path source, // $ positiveSinkExample=copy(Path,OutputStream):Argument[0](path-injection) // manual model exists
14-
OutputStream out // $ sinkModel=copy(Path,OutputStream):Argument[1]
14+
OutputStream out // $ sinkModelCandidate=copy(Path,OutputStream):Argument[1]
1515
/* NB: may be worthwhile to implement the
1616
same behavior as in application mode where out would not be a
1717
candidate because there already is a model for another parameter of
@@ -22,9 +22,9 @@ public static void copy( // method result is not a candidate source (void)
2222
// ...
2323
}
2424

25-
public static InputStream newInputStream( // $ sourceModel=newInputStream(Path,OpenOption[]):ReturnValue
26-
Path openPath, // $ positiveSinkExample=newInputStream(Path,OpenOption[]):Argument[0](path-injection) sinkModel=newInputStream(Path,OpenOption[]):Argument[0] // known sink, but still a candidate (ai-modeled, and useful as a candidate in regression testing)
27-
OpenOption... options // $ sinkModel=newInputStream(Path,OpenOption[]):Argument[1]
25+
public static InputStream newInputStream( // $ sourceModelCandidate=newInputStream(Path,OpenOption[]):ReturnValue
26+
Path openPath, // $ positiveSinkExample=newInputStream(Path,OpenOption[]):Argument[0](path-injection) sinkModelCandidate=newInputStream(Path,OpenOption[]):Argument[0] // known sink, but still a candidate (ai-modeled, and useful as a candidate in regression testing)
27+
OpenOption... options // $ sinkModelCandidate=newInputStream(Path,OpenOption[]):Argument[1]
2828
) throws IOException {
2929
return new FileInputStream(openPath.toFile());
3030
}

0 commit comments

Comments
 (0)