Skip to content

Commit a3f6bfe

Browse files
committed
commandargs sources
1 parent 51afe12 commit a3f6bfe

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-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: 19 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 {
@@ -30,9 +31,27 @@ class TextFieldSource extends LocalUserInputSource {
3031
override string getSourceType() { result = "TextBox text" }
3132
}
3233

34+
/**
35+
* A dataflow source that represents the access of an environment variable.
36+
*/
3337
abstract class EnvironmentVariableSource extends LocalFlowSource {
3438
override string getThreatModel() { result = "environment" }
3539

3640
override string getSourceType() { result = "environment variable" }
3741
}
3842

43+
/**
44+
* A dataflow source that represents the access of a command line argument.
45+
*/
46+
abstract class CommandLineArgumentSource extends LocalFlowSource {
47+
override string getThreatModel() { result = "commandargs" }
48+
49+
override string getSourceType() { result = "command line argument" }
50+
}
51+
52+
/**
53+
* A data flow source that represents the parameters of the `Main` method of a program.
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)