Skip to content

Commit 1d9d878

Browse files
committed
C#: Remove some false positives and add more true positives for cs/invalid-string-format.
1 parent f73b742 commit 1d9d878

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/Format.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private class StringAndStringBuilderFormatMethods extends FormatMethod {
4141
private class SystemConsoleAndSystemIoTextWriterFormatMethods extends FormatMethod {
4242
SystemConsoleAndSystemIoTextWriterFormatMethods() {
4343
this.getParameter(0).getType() instanceof StringType and
44+
this.getNumberOfParameters() > 1 and
4445
exists(Class declType | declType = this.getDeclaringType() |
4546
this.hasName(["Write", "WriteLine"]) and
4647
(
@@ -67,6 +68,7 @@ private class SystemDiagnosticsDebugAssert extends FormatMethod {
6768
private class SystemDiagnosticsFormatMethods extends FormatMethod {
6869
SystemDiagnosticsFormatMethods() {
6970
this.getParameter(0).getType() instanceof StringType and
71+
this.getNumberOfParameters() > 1 and
7072
exists(Class declType |
7173
declType = this.getDeclaringType() and
7274
declType.getNamespace().getFullName() = "System.Diagnostics"

csharp/ql/src/API Abuse/FormatInvalid.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ private predicate invalidFormatString(
2929
source.getNode().asExpr() = src and
3030
sink.getNode().asExpr() = call.getFormatExpr() and
3131
FormatInvalid::flowPath(source, sink) and
32-
call.hasInsertions() and
3332
msg = "Invalid format string used in $@ formatting call." and
3433
callString = "this"
3534
}

0 commit comments

Comments
 (0)