Merge pull request #5308 from tamasvajk/feature/flow-sources-sinks · ayoubRT/codeql@a7030c7 · GitHub
Skip to content

Commit a7030c7

Browse files
authored
Merge pull request github#5308 from tamasvajk/feature/flow-sources-sinks
C#: Add Console.Read* to local flow sources
2 parents c3058f4 + 1b4c3c7 commit a7030c7

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions

‎csharp/ql/src/semmle/code/csharp/security/dataflow/flowsources/Local.qll‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ class TextFieldSource extends LocalUserInputSource {
2020

2121
override string getSourceType() { result = "TextBox text" }
2222
}
23+
24+
/** A call to any `System.Console.Read*` method. */
25+
class SystemConsoleReadSource extends LocalUserInputSource {
26+
SystemConsoleReadSource() {
27+
this.asExpr() =
28+
any(MethodCall call |
29+
call.getTarget().hasQualifiedName("System.Console", ["ReadLine", "Read", "ReadKey"])
30+
)
31+
}
32+
33+
override string getSourceType() { result = "System.Console input" }
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System;
3+
4+
public class Program
5+
{
6+
public static void Main()
7+
{
8+
var format = Console.ReadLine();
9+
10+
// BAD: Uncontrolled format string.
11+
var x = string.Format(format, 1, 2);
12+
}
13+
}

‎csharp/ql/test/query-tests/Security Features/CWE-134/UncontrolledFormatString.expected‎

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)