Java: Automodel Fr Mode: add return value endpoint type

This commit is contained in:
Stephan Brandauer
2023-09-12 09:28:34 +02:00
parent 8cc6466c68
commit b2578f0e30
4 changed files with 35 additions and 10 deletions

View File

@@ -25,7 +25,8 @@ newtype JavaRelatedLocationType =
newtype TFrameworkModeEndpoint =
TExplicitParameter(Parameter p) or
TQualifier(Callable c)
TQualifier(Callable c) or
TReturnValue(Callable c)
/**
* A framework mode endpoint.
@@ -48,9 +49,7 @@ abstract class FrameworkModeEndpoint extends TFrameworkModeEndpoint {
abstract Top asTop();
string getExtensibleType() {
result = "sinkModel"
}
abstract string getExtensibleType();
string toString() { result = this.asTop().toString() }
@@ -69,6 +68,8 @@ class ExplicitParameterEndpoint extends FrameworkModeEndpoint, TExplicitParamete
override Callable getEnclosingCallable() { result = param.getCallable() }
override Top asTop() { result = param }
override string getExtensibleType() { result = "sinkModel" }
}
class QualifierEndpoint extends FrameworkModeEndpoint, TQualifier {
@@ -85,6 +86,30 @@ class QualifierEndpoint extends FrameworkModeEndpoint, TQualifier {
override Callable getEnclosingCallable() { result = callable }
override Top asTop() { result = callable }
override string getExtensibleType() { result = "sinkModel" }
}
class ReturnValue extends FrameworkModeEndpoint, TReturnValue {
Callable callable;
ReturnValue() { this = TReturnValue(callable) and callable.fromSource() }
override int getIndex() {
// FIXME bogus value
result = -1
}
override string getParamName() {
// FIXME bogus value
result = "return value"
}
override Callable getEnclosingCallable() { result = callable }
override Top asTop() { result = callable }
override string getExtensibleType() { result = "sourceModel" }
}
/**

View File

@@ -3,11 +3,11 @@ package com.github.codeql.test;
public class PublicClass {
public void stuff(String arg) { // `arg` is a candidate, `this` is a candidate
System.out.println(arg);
}
} // method stuff is a candidate source
public static void staticStuff(String arg) { // `arg` is a candidate, `this` is not a candidate (static method)
System.out.println(arg);
}
} // method staticStuff is a candidate source
// `arg` and `this` are not a candidate because the method is not public:
protected void nonPublicStuff(String arg) {

View File

@@ -1,9 +1,9 @@
package com.github.codeql.test;
public interface PublicInterface {
public void stuff(String arg); // `arg` is a candidate, `this` is a candidate
public void stuff(String arg); // `arg` is a candidate, `this` is a candidate, method stuff is a candidate source
public static void staticStuff(String arg) { // `arg` is a candidate, `this` is not a candidate (static method)
System.out.println(arg);
}
} // method staticStuff is a candidate source
}

View File

@@ -19,12 +19,12 @@ public class Files {
*/
) throws IOException {
// ...
}
} // method copy is a candidate source
public static InputStream newInputStream(
Path openPath ,// positive example (known sink), candidate (ai-modeled, and useful as a candidate in regression testing)
OpenOption... options
) throws IOException {
return new FileInputStream(openPath.toFile());
}
} // method newInputStream is a candidate source
}