Skip to content

Commit 9887e2b

Browse files
committed
Merge branch 'main' into alamofire2
2 parents 3e6eede + 4b9b35d commit 9887e2b

File tree

37 files changed

+1585
-3571
lines changed

37 files changed

+1585
-3571
lines changed

csharp/ql/consistency-queries/SsaConsistency.ql

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
import csharp
2-
import semmle.code.csharp.dataflow.internal.SsaImpl::Consistency as Consistency
2+
import semmle.code.csharp.dataflow.internal.SsaImpl::Consistency
33
import Ssa
44

5-
class MyRelevantDefinition extends Consistency::RelevantDefinition, Ssa::Definition {
5+
class MyRelevantDefinition extends RelevantDefinition, Ssa::Definition {
66
override predicate hasLocationInfo(
77
string filepath, int startline, int startcolumn, int endline, int endcolumn
88
) {
99
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
1010
}
1111
}
1212

13-
query predicate nonUniqueDef = Consistency::nonUniqueDef/4;
14-
15-
query predicate readWithoutDef = Consistency::readWithoutDef/3;
16-
17-
query predicate deadDef = Consistency::deadDef/2;
18-
19-
query predicate notDominatedByDef = Consistency::notDominatedByDef/4;
20-
2113
query predicate localDeclWithSsaDef(LocalVariableDeclExpr d) {
2214
// Local variables in C# must be initialized before every use, so uninitialized
2315
// local variables should not have an SSA definition, as that would imply that

go/extractor/trap/labels.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (l *Labeler) GlobalID(key string) Label {
5757
label, exists := l.keyLabels[key]
5858
if !exists {
5959
id := l.nextID()
60-
fmt.Fprintf(l.tw.zip, "%s=@\"%s\"\n", id, escapeString(key))
60+
fmt.Fprintf(l.tw.wzip, "%s=@\"%s\"\n", id, escapeString(key))
6161
label = Label{id}
6262
l.keyLabels[key] = label
6363
}
@@ -90,7 +90,7 @@ func (l *Labeler) LocalID(nd interface{}) Label {
9090
// FreshID creates a fresh label and returns it
9191
func (l *Labeler) FreshID() Label {
9292
id := l.nextID()
93-
fmt.Fprintf(l.tw.zip, "%s=*\n", id)
93+
fmt.Fprintf(l.tw.wzip, "%s=*\n", id)
9494
return Label{id}
9595
}
9696

go/extractor/trap/trapwriter.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
// A Writer provides methods for writing data to a TRAP file
2020
type Writer struct {
2121
zip *gzip.Writer
22-
w *bufio.Writer
22+
wzip *bufio.Writer
23+
wfile *bufio.Writer
2324
file *os.File
2425
Labeler *Labeler
2526
path string
@@ -54,11 +55,13 @@ func NewWriter(path string, pkg *packages.Package) (*Writer, error) {
5455
if err != nil {
5556
return nil, err
5657
}
57-
bufioWriter := bufio.NewWriter(tmpFile)
58-
zipWriter := gzip.NewWriter(bufioWriter)
58+
bufioFileWriter := bufio.NewWriter(tmpFile)
59+
zipWriter := gzip.NewWriter(bufioFileWriter)
60+
bufioZipWriter := bufio.NewWriter(zipWriter)
5961
tw := &Writer{
6062
zipWriter,
61-
bufioWriter,
63+
bufioZipWriter,
64+
bufioFileWriter,
6265
tmpFile,
6366
nil,
6467
path,
@@ -88,13 +91,19 @@ func trapFolder() (string, error) {
8891

8992
// Close the underlying file writer
9093
func (tw *Writer) Close() error {
91-
err := tw.zip.Close()
94+
err := tw.wzip.Flush()
95+
if err != nil {
96+
// throw away file close error
97+
tw.file.Close()
98+
return err
99+
}
100+
err = tw.zip.Close()
92101
if err != nil {
93102
// return zip-close error, but ignore file-close error
94103
tw.file.Close()
95104
return err
96105
}
97-
err = tw.w.Flush()
106+
err = tw.wfile.Flush()
98107
if err != nil {
99108
// throw away close error because write errors are likely to be more important
100109
tw.file.Close()
@@ -145,24 +154,24 @@ func capStringLength(s string) string {
145154

146155
// Emit writes out a tuple of values for the given `table`
147156
func (tw *Writer) Emit(table string, values []interface{}) error {
148-
fmt.Fprintf(tw.zip, "%s(", table)
157+
fmt.Fprintf(tw.wzip, "%s(", table)
149158
for i, value := range values {
150159
if i > 0 {
151-
fmt.Fprint(tw.zip, ", ")
160+
fmt.Fprint(tw.wzip, ", ")
152161
}
153162
switch value := value.(type) {
154163
case Label:
155-
fmt.Fprint(tw.zip, value.id)
164+
fmt.Fprint(tw.wzip, value.id)
156165
case string:
157-
fmt.Fprintf(tw.zip, "\"%s\"", escapeString(capStringLength(value)))
166+
fmt.Fprintf(tw.wzip, "\"%s\"", escapeString(capStringLength(value)))
158167
case int:
159-
fmt.Fprintf(tw.zip, "%d", value)
168+
fmt.Fprintf(tw.wzip, "%d", value)
160169
case float64:
161-
fmt.Fprintf(tw.zip, "%e", value)
170+
fmt.Fprintf(tw.wzip, "%e", value)
162171
default:
163172
return errors.New("Cannot emit value")
164173
}
165174
}
166-
fmt.Fprintf(tw.zip, ")\n")
175+
fmt.Fprintf(tw.wzip, ")\n")
167176
return nil
168177
}

java/kotlin-extractor/src/main/kotlin/utils/Logger.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ open class LoggerBase(val logCounter: LogCounter) {
138138
fullMsgBuilder.append(suffix)
139139

140140
val fullMsg = fullMsgBuilder.toString()
141+
emitDiagnostic(tw, severity, diagnosticLocStr, msg, fullMsg, locationString, mkLocationId)
142+
}
143+
144+
private fun emitDiagnostic(tw: TrapWriter, severity: Severity, diagnosticLocStr: String, msg: String, fullMsg: String, locationString: String? = null, mkLocationId: () -> Label<DbLocation> = { tw.unknownLocation }) {
141145
val locStr = if (locationString == null) "" else "At " + locationString + ": "
142146
val kind = if (severity <= Severity.WarnHigh) "WARN" else "ERROR"
143147
val logMessage = LogMessage(kind, "Diagnostic($diagnosticLocStr): $locStr$fullMsg")
@@ -190,9 +194,10 @@ open class LoggerBase(val logCounter: LogCounter) {
190194
// We don't know if this location relates to an error
191195
// or a warning, so we just declare hitting the limit
192196
// to be an error regardless.
193-
val logMessage = LogMessage("ERROR", "Total of $count diagnostics from $caller.")
194-
tw.writeComment(logMessage.toText())
195-
logStream.write(logMessage.toJsonLine())
197+
val message = "Total of $count diagnostics (reached limit of ${logCounter.diagnosticLimit}) from $caller."
198+
if (verbosity >= 1) {
199+
emitDiagnostic(tw, Severity.Error, "Limit", message, message)
200+
}
196201
}
197202
}
198203
}

java/ql/src/Telemetry/ExtractorInformation.ql

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import java
1010
import semmle.code.java.Diagnostics
1111

12+
predicate compilationInfo(string key, int value) {
13+
exists(Compilation c, string infoKey |
14+
key = infoKey + ": " + c.getInfo(infoKey) and
15+
value = 1
16+
)
17+
}
18+
1219
predicate fileCount(string key, int value) {
1320
key = "Number of files" and
1421
value = strictcount(File f)
@@ -53,13 +60,38 @@ predicate extractorDiagnostics(string key, int value) {
5360
)
5461
}
5562

63+
/*
64+
* Just counting the diagnostics doesn't give the full picture, as
65+
* CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT means that some diagnostics
66+
* will be suppressed. In that case, we need to look for the
67+
* suppression message, uncount those that did get emitted, uncount the
68+
* suppression message itself, and then add on the full count.
69+
*/
70+
71+
predicate extractorTotalDiagnostics(string key, int value) {
72+
exists(string extractor, string limitRegex |
73+
limitRegex = "Total of ([0-9]+) diagnostics \\(reached limit of ([0-9]+)\\).*" and
74+
key = "Total number of diagnostics from " + extractor and
75+
value =
76+
strictcount(Diagnostic d | d.getGeneratedBy() = extractor) +
77+
sum(Diagnostic d |
78+
d.getGeneratedBy() = extractor
79+
|
80+
d.getMessage().regexpCapture(limitRegex, 1).toInt() -
81+
d.getMessage().regexpCapture(limitRegex, 2).toInt() - 1
82+
)
83+
)
84+
}
85+
5686
from string key, int value
5787
where
88+
compilationInfo(key, value) or
5889
fileCount(key, value) or
5990
fileCountByExtension(key, value) or
6091
totalNumberOfLines(key, value) or
6192
numberOfLinesOfCode(key, value) or
6293
totalNumberOfLinesByExtension(key, value) or
6394
numberOfLinesOfCodeByExtension(key, value) or
64-
extractorDiagnostics(key, value)
95+
extractorDiagnostics(key, value) or
96+
extractorTotalDiagnostics(key, value)
6597
select key, value

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/ATMConfig.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ abstract class AtmConfig extends string {
5050
// known sink for the class.
5151
exists(EndpointCharacteristic characteristic |
5252
characteristic.getEndpoints(sink) and
53-
characteristic.getImplications(this.getASinkEndpointType(), true, 1.0)
53+
characteristic
54+
.getImplications(this.getASinkEndpointType(), true, characteristic.maximalConfidence())
5455
)
5556
}
5657

0 commit comments

Comments
 (0)