Skip to content

Commit 8a58af8

Browse files
committed
PS: Add a model for 'EscapeSingleQuotedStringContent' and add a test.
1 parent 65abf48 commit 8a58af8

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

powershell/ql/lib/semmle/code/powershell/frameworks/SystemManagementAutomation/model.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,3 +1820,9 @@ extensions:
18201820
- ["System.Collections.ObjectModel.ReadOnlyCollection<System.Management.Automation.PSTypeName>", "System.Management.Automation.FunctionInfo", "Property[OutputType]"]
18211821
- ["System.Management.Automation.Language.ParseError[]", "System.Management.Automation.ParseException", "Property[Errors]"]
18221822
- ["System.Management.Automation.DSCResourceRunAsCredential", "System.Management.Automation.DscResourceAttribute", "Property[RunAsCredential]"]
1823+
1824+
- addsTo:
1825+
pack: microsoft-sdl/powershell-all
1826+
extensible: summaryModel
1827+
data:
1828+
- ["System.Management.Automation.Language.CodeGeneration!", "Method[escapesinglequotedstringcontent]", "Argument[0]", "ReturnValue", "taint"]

powershell/ql/test/library-tests/dataflow/local/taint.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
12
| test.ps1:1:1:1:3 | a1 | test.ps1:2:6:2:8 | a1 |
23
| test.ps1:1:1:24:22 | implicit unwrapping of {...} | test.ps1:1:1:24:22 | return value for {...} |
34
| test.ps1:1:1:24:22 | pre-return value for {...} | test.ps1:1:1:24:22 | implicit unwrapping of {...} |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
models
2+
edges
3+
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | provenance | |
4+
| test.ps1:1:6:1:15 | Call to Source | test.ps1:2:94:2:95 | x | provenance | |
5+
| test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | test.ps1:3:6:3:7 | y | provenance | |
6+
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | provenance | |
7+
| test.ps1:2:94:2:95 | x | test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | provenance | |
8+
nodes
9+
| file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
10+
| file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | semmle.label | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] |
11+
| test.ps1:1:6:1:15 | Call to Source | semmle.label | Call to Source |
12+
| test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent | semmle.label | Call to EscapeSingleQuotedStringContent |
13+
| test.ps1:2:94:2:95 | x | semmle.label | x |
14+
| test.ps1:3:6:3:7 | y | semmle.label | y |
15+
subpaths
16+
| test.ps1:2:94:2:95 | x | file://:0:0:0:0 | [summary param] pos(0, {}) in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | file://:0:0:0:0 | [summary] to write: ReturnValue in System.Management.Automation.Language.CodeGeneration!;Method[escapesinglequotedstringcontent] | test.ps1:2:6:2:96 | Call to EscapeSingleQuotedStringContent |
17+
testFailures
18+
#select
19+
| test.ps1:3:6:3:7 | y | test.ps1:1:6:1:15 | Call to Source | test.ps1:3:6:3:7 | y | $@ | test.ps1:1:6:1:15 | Call to Source | Call to Source |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import powershell
6+
import semmle.code.powershell.dataflow.DataFlow
7+
private import TestUtilities.InlineFlowTest
8+
import DefaultFlowTest
9+
import TaintFlow::PathGraph
10+
11+
from TaintFlow::PathNode source, TaintFlow::PathNode sink
12+
where TaintFlow::flowPath(source, sink)
13+
select sink, source, sink, "$@", source, source.toString()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$x = Source "1"
2+
$y = [System.Management.Automation.Language.CodeGeneration]::EscapeSingleQuotedStringContent($x)
3+
Sink $y # $ hasTaintFlow=1

0 commit comments

Comments
 (0)