Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go/ql/lib/change-notes/2024-12-13-os-args-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: minorAnalysis
---
* Added a `commandargs` local source model for the `os.Args` variable.

6 changes: 6 additions & 0 deletions go/ql/lib/semmle/go/frameworks/stdlib/Os.qll
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ module Os {
input = inp and output = outp
}
}

private class ArgsSource extends SourceNode {
ArgsSource() { exists(Variable v | v.hasQualifiedName("os", "Args") | this = v.getARead()) }

override string getThreatModel() { result = "commandargs" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testFailures
invalidModelRow
failures
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extensions:
- addsTo:
pack: codeql/threat-models
extensible: threatModelConfiguration
data:
- ["commandargs", true, 0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import go

Check failure on line 1 in go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql

View workflow job for this annotation

GitHub Actions / Test Linux (Ubuntu)

[309/576 comp 8.8s eval 226ms] FAILED(RESULT) /home/runner/work/codeql/codeql/go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/commandargs/test.ql
import ModelValidation
import TestUtilities.InlineExpectationsTest

module SourceTest implements TestSig {
string getARelevantTag() { result = "source" }

predicate hasActualResult(Location location, string element, string tag, string value) {
exists(ActiveThreatModelSource s |
s.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
element = s.toString() and
value = "" and
tag = "source"
)
}
}

import MakeTest<SourceTest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package test

import "os"

func loopThroughCommandArgs() {
for _, arg := range os.Args { // $ source
_ = arg
}
}
Loading