Skip to content

Commit

Permalink
Update Go version in CI script (#913)
Browse files Browse the repository at this point in the history
* Update Go version in CI script

* Introduce back an additional check for filepath clean to fix the unit tests
  • Loading branch information
ccojocar authored Jan 9, 2023
1 parent 5874e63 commit c5d217d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
strategy:
matrix:
go_version:
- '1.18.8' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
- '1.19.3' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
- '1.18.9' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
- '1.19.4' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
runs-on: ubuntu-latest
env:
GO111MODULE: on
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: '1.19.2' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
go-version: '1.19.4' # TODO: remove this once actions/setup-go@v3 uses latest as latest; see https://github.com/securego/gosec/pull/880
- name: Checkout Source
uses: actions/checkout@v3
- uses: actions/cache@v3
Expand Down
14 changes: 12 additions & 2 deletions rules/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ func (r *readfile) isJoinFunc(n ast.Node, c *gosec.Context) bool {
}

// isFilepathClean checks if there is a filepath.Clean for given variable
func (r *readfile) isFilepathClean(n *ast.Ident) bool {
func (r *readfile) isFilepathClean(n *ast.Ident, c *gosec.Context) bool {
if _, ok := r.cleanedVar[n.Obj.Decl]; ok {
return true
}
if n.Obj.Kind != ast.Var {
return false
}
if node, ok := n.Obj.Decl.(*ast.AssignStmt); ok {
if call, ok := node.Rhs[0].(*ast.CallExpr); ok {
if clean := r.clean.ContainsPkgCallExpr(call, c, false); clean != nil {
return true
}
}
}
return false
}

Expand Down Expand Up @@ -101,7 +111,7 @@ func (r *readfile) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
obj := c.Info.ObjectOf(ident)
if _, ok := obj.(*types.Var); ok &&
!gosec.TryResolve(ident, c) &&
!r.isFilepathClean(ident) {
!r.isFilepathClean(ident, c) {
return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil
}
}
Expand Down

0 comments on commit c5d217d

Please sign in to comment.