Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#/Java: Parameterized module for model printing. #16775

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add parameterized module for MaD model printing.
  • Loading branch information
michaelnebel committed Jun 24, 2024
commit 65e150b41636c9c2d90a1ed6a7146ed86830b8c4
120 changes: 120 additions & 0 deletions shared/mad/codeql/mad/modelgenerator/ModelPrinting.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
signature module ModelPrintingLangSig {
/**
* A class of callables.
*/
class Callable;

/**
* Holds if `container`, `type`, `name`, and `parameters` contain the type signature of `api`
* and `extensible` is the string representation of a boolean that is true, if
* `api` can be overridden (otherwise false).
*/
predicate partialModel(
Callable api, string container, string type, string extensible, string name, string parameters
);
}

module ModelPrintingImpl<ModelPrintingLangSig Lang> {
signature module ModelPrintingSig {
/**
* The class of APIs relevant for model generation.
*/
class Api extends Lang::Callable {
Lang::Callable lift();
}

/**
* Gets the string representation of the provenance of the models.
*/
string getProvenance();
}

module ModelPrinting<ModelPrintingSig Printing> {
/**
* Computes the first 6 columns for MaD rows used for summaries, sources and sinks.
*/
private string asPartialModel(Printing::Api api) {
exists(string container, string type, string extensible, string name, string parameters |
Lang::partialModel(api.lift(), container, type, extensible, name, parameters) and
result =
container + ";" //
+ type + ";" //
+ extensible + ";" //
+ name + ";" //
+ parameters + ";" //
+ /* ext + */ ";" //
)
}

/**
* Computes the first 4 columns for neutral MaD rows.
*/
private string asPartialNeutralModel(Printing::Api api) {
exists(string container, string type, string name, string parameters |
Lang::partialModel(api, container, type, _, name, parameters) and
result =
container + ";" //
+ type + ";" //
+ name + ";" //
+ parameters + ";" //
)
}

/**
* Gets the summary model for `api` with `input`, `output` and `kind`.
*/
bindingset[input, output, kind]
private string asSummaryModel(Printing::Api api, string input, string output, string kind) {
result =
asPartialModel(api) + input + ";" //
+ output + ";" //
+ kind + ";" //
+ Printing::getProvenance()
}

string asNeutralSummaryModel(Printing::Api api) {
result =
asPartialNeutralModel(api) //
+ "summary" + ";" //
+ Printing::getProvenance()
}

/**
* Gets the value summary model for `api` with `input` and `output`.
*/
bindingset[input, output]
string asValueModel(Printing::Api api, string input, string output) {
result = asSummaryModel(api, input, output, "value")
}

/**
* Gets the taint summary model for `api` with `input` and `output`.
*/
bindingset[input, output]
string asTaintModel(Printing::Api api, string input, string output) {
result = asSummaryModel(api, input, output, "taint")
}

/**
* Gets the sink model for `api` with `input` and `kind`.
*/
bindingset[input, kind]
string asSinkModel(Printing::Api api, string input, string kind) {
result =
asPartialModel(api) + input + ";" //
+ kind + ";" //
+ Printing::getProvenance()
}

/**
* Gets the source model for `api` with `output` and `kind`.
*/
bindingset[output, kind]
string asSourceModel(Printing::Api api, string output, string kind) {
result =
asPartialModel(api) + output + ";" //
+ kind + ";" //
+ Printing::getProvenance()
}
}
}