Merge pull request #11499 from michaelnebel/java/kotlinstd

Kotlin: Migrate standard library models to data extensions.
This commit is contained in:
Michael Nebel
2022-12-02 14:44:50 +01:00
committed by GitHub
12 changed files with 6513 additions and 6312 deletions

View File

@@ -0,0 +1,14 @@
/**
* @name Extract MaD negative summary model rows.
* @description This extracts the Models as data negative summary model rows.
* @id csharp/utils/modelconverter/generate-data-extensions-negative-summary
*/
import csharp
import semmle.code.csharp.dataflow.ExternalFlow
from string package, string type, string name, string signature, string provenance
where
negativeSummaryModel(package, type, name, signature, provenance) and
provenance != "generated"
select package, type, name, signature, provenance order by package, type, name, signature

File diff suppressed because it is too large Load Diff

View File

@@ -98,7 +98,6 @@ private module Frameworks {
private import semmle.code.java.frameworks.apache.Collections
private import semmle.code.java.frameworks.apache.Lang
private import semmle.code.java.frameworks.Flexjson
private import semmle.code.java.frameworks.generated
private import semmle.code.java.frameworks.guava.Guava
private import semmle.code.java.frameworks.jackson.JacksonSerializability
private import semmle.code.java.frameworks.javaee.jsf.JSFRenderer
@@ -135,7 +134,7 @@ private module Frameworks {
*
* Extend this class to add additional source definitions.
*/
class SourceModelCsv = SourceModelCsvInternal;
deprecated class SourceModelCsv = SourceModelCsvInternal;
private class SourceModelCsvInternal extends Unit {
/** Holds if `row` specifies a source definition. */
@@ -149,7 +148,7 @@ private class SourceModelCsvInternal extends Unit {
*
* Extend this class to add additional sink definitions.
*/
class SinkModelCsv = SinkModelCsvInternal;
deprecated class SinkModelCsv = SinkModelCsvInternal;
private class SinkModelCsvInternal extends Unit {
/** Holds if `row` specifies a sink definition. */
@@ -163,7 +162,7 @@ private class SinkModelCsvInternal extends Unit {
*
* Extend this class to add additional flow summary definitions.
*/
class SummaryModelCsv = SummaryModelCsvInternal;
deprecated class SummaryModelCsv = SummaryModelCsvInternal;
private class SummaryModelCsvInternal extends Unit {
/** Holds if `row` specifies a summary definition. */
@@ -177,7 +176,7 @@ private class SummaryModelCsvInternal extends Unit {
*
* Extend this class to add additional negative summary definitions.
*/
class NegativeSummaryModelCsv = NegativeSummaryModelCsvInternal;
deprecated class NegativeSummaryModelCsv = NegativeSummaryModelCsvInternal;
private class NegativeSummaryModelCsvInternal extends Unit {
/** Holds if `row` specifies a negative summary definition. */
@@ -555,7 +554,7 @@ module ModelValidation {
not type.regexpMatch("[a-zA-Z0-9_\\$<>]+") and
result = "Dubious type \"" + type + "\" in " + pred + " model."
or
not name.regexpMatch("[a-zA-Z0-9_]*") and
not name.regexpMatch("[a-zA-Z0-9_\\-]*") and
result = "Dubious name \"" + name + "\" in " + pred + " model."
or
not signature.regexpMatch("|\\([a-zA-Z0-9_\\.\\$<>,\\[\\]]*\\)") and

View File

@@ -1,9 +0,0 @@
/**
* A module importing all generated Models as Data models.
*/
import java
private module GeneratedFrameworks {
private import kotlin.StdLibGenerated
}

View File

@@ -0,0 +1,14 @@
/**
* @name Extract MaD negative summary model rows.
* @description This extracts the Models as data negative summary model rows.
* @id java/utils/modelconverter/generate-data-extensions-negative-summary
*/
import java
import semmle.code.java.dataflow.ExternalFlow
from string package, string type, string name, string signature, string provenance
where
negativeSummaryModel(package, type, name, signature, provenance) and
provenance != "generated"
select package, type, name, signature, provenance order by package, type, name, signature

View File

@@ -1,7 +0,0 @@
/**
* CSV Validation of negative summaries.
*/
import java
import semmle.code.java.dataflow.ExternalFlow
import ModelValidation

View File

@@ -74,7 +74,8 @@ class Converter:
summaries = self.getAddsTo("ExtractSummaries.ql", helpers.summaryModelPredicate)
sources = self.getAddsTo("ExtractSources.ql", helpers.sourceModelPredicate)
sinks = self.getAddsTo("ExtractSinks.ql", helpers.sinkModelPredicate)
return merge(sources, sinks, summaries)
negativeSummaries = self.getAddsTo("ExtractNegativeSummaries.ql", helpers.negativeSummaryModelPredicate)
return merge(sources, sinks, summaries, negativeSummaries)
def save(self, extensions):

View File

@@ -169,7 +169,7 @@ Requirements: `codeql` should both appear on your path.
sourceAddsTo = ""
if self.generateNegativeSummaries:
negativeSummaryAddsTo = self.getAddsTo("CaptureNegativeSummaryModels.ql", "extNegativeSummaryModel")
negativeSummaryAddsTo = self.getAddsTo("CaptureNegativeSummaryModels.ql", helpers.negativeSummaryModelPredicate)
else:
negativeSummaryAddsTo = ""
@@ -180,8 +180,7 @@ extensions:
{sinkAddsTo}
{sourceAddsTo}
{summaryAddsTo}
{negativeSummaryAddsTo}
"""
{negativeSummaryAddsTo}"""
def makeTypeBasedContent(self):
if self.generateTypeBasedSummaries:
@@ -189,13 +188,11 @@ extensions:
else:
typeBasedSummaryAddsTo = ""
return f"""
# THIS FILE IS AN AUTO-GENERATED MODELS AS DATA FILE. DO NOT EDIT.
return f"""# THIS FILE IS AN AUTO-GENERATED MODELS AS DATA FILE. DO NOT EDIT.
# Definitions of type based summaries in the {self.friendlyname} framework.
extensions:
{typeBasedSummaryAddsTo}
"""
{typeBasedSummaryAddsTo}"""
def save(self, content, target):
with open(target, "w") as targetYml:

View File

@@ -7,6 +7,7 @@ import subprocess
summaryModelPredicate = "extSummaryModel"
sinkModelPredicate = "extSinkModel"
sourceModelPredicate = "extSourceModel"
negativeSummaryModelPredicate = "extNegativeSummaryModel"
addsToTemplate = """ - addsTo:
pack: {0}
extensible: {1}