Skip to content

Commit 0a7e00f

Browse files
committed
commandargs sources
1 parent c0474b8 commit 0a7e00f

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

csharp/ql/lib/ext/System.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extensions:
77
- ["System", "Console", False, "ReadKey", "", "", "ReturnValue", "local", "manual"]
88
- ["System", "Console", False, "ReadLine", "", "", "ReturnValue", "local", "manual"]
99
- ["System", "Environment", False, "ExpandEnvironmentVariables", "", "", "ReturnValue", "environment", "manual"]
10+
- ["System", "Environment", False, "GetCommandLineArgs", "", "", "ReturnValue", "commandargs", "manual"]
11+
- ["System", "Environment", False, "get_CommandLine", "", "", "ReturnValue", "commandargs", "manual"]
1012
- ["System", "Environment", False, "GetEnvironmentVariable", "", "", "ReturnValue", "environment", "manual"]
1113
- ["System", "Environment", False, "GetEnvironmentVariables", "", "", "ReturnValue", "environment", "manual"]
1214
- addsTo:

csharp/ql/lib/semmle/code/csharp/security/dataflow/flowsources/Local.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import csharp
66
private import semmle.code.csharp.frameworks.system.windows.Forms
77
private import semmle.code.csharp.dataflow.internal.ExternalFlow
88
private import semmle.code.csharp.security.dataflow.flowsources.FlowSources
9+
private import semmle.code.csharp.commons.Util
910

1011
/** A data flow source of local data. */
1112
abstract class LocalFlowSource extends SourceNode {
@@ -37,3 +38,20 @@ abstract class EnvironmentVariableSource extends LocalFlowSource {
3738
override string getSourceType() { result = "environment variable" }
3839
}
3940

41+
abstract class CommandLineArgumentSource extends LocalFlowSource {
42+
override string getThreatModel() { result = "commandargs" }
43+
44+
override string getSourceType() { result = "command line argument" }
45+
}
46+
47+
// private class SystemEnvironmentCommandLineSource extends CommandLineArgumentSource {
48+
// SystemEnvironmentCommandLineSource() {
49+
// exists(PropertyAccess pa | this.asExpr() = pa |
50+
// pa.getTarget().hasName("CommandLine") and
51+
// pa.getTarget().getDeclaringType().hasFullyQualifiedName("System", "Environment")
52+
// )
53+
// }
54+
// }
55+
private class MainMethodArgumentSource extends CommandLineArgumentSource {
56+
MainMethodArgumentSource() { this.asParameter() = any(MainMethod mainMethod).getAParameter() }
57+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace CommandArgs
4+
{
5+
class CommandArgsUse
6+
{
7+
public static void M1()
8+
{
9+
string result = Environment.GetCommandLineArgs()[0];
10+
}
11+
12+
public static void M2()
13+
{
14+
string result = Environment.CommandLine;
15+
}
16+
}
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| CommandArgs.cs:9:29:9:60 | call to method GetCommandLineArgs |
2+
| CommandArgs.cs:14:29:14:51 | access to property CommandLine |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import csharp
2+
import semmle.code.csharp.dataflow.internal.ExternalFlow
3+
4+
from DataFlow::Node source
5+
where sourceNode(source, "commandargs")
6+
select source

0 commit comments

Comments
 (0)