Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

internal/fileutils/contains.go:40:12: G304: Potential file inclusion via variable (gosec) #106

Closed
atc0005 opened this issue Jul 21, 2020 · 3 comments · Fixed by #114
Closed
Assignees
Labels
bug Something isn't working linting
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Jul 21, 2020

Found this after using --exclude-use-default=false with version v1.29.0.

$ golangci-lint run -v --exclude-use-default=false
# ...
internal/fileutils/contains.go:40:12: G304: Potential file inclusion via variable (gosec)
        f, err := os.Open(filename)
                  ^
@atc0005 atc0005 added bug Something isn't working linting labels Jul 21, 2020
@atc0005 atc0005 self-assigned this Jul 21, 2020
@atc0005 atc0005 added this to the Next Release milestone Jul 21, 2020
@atc0005
Copy link
Owner Author

atc0005 commented Jul 22, 2020

@atc0005
Copy link
Owner Author

atc0005 commented Jul 22, 2020

@atc0005
Copy link
Owner Author

atc0005 commented Jul 22, 2020

I tried to set a cleanFilename variable some number of lines earlier and use that, but it is still a variable and still fails the check.

Instead, I have to use an explicit filepath.Clean(filename) call at the point where the linting error was being raised. Since I'm logging the original and the sanitized version of the filename it feels redundant to call filepath.Clean twice, but it's a small price to pay to build better habits.

atc0005 added a commit that referenced this issue Jul 22, 2020
Instead of using the original value as-is or attempting to
create a localized "cleanFilename" var, use filepath.Clean
directly at the os.Open call. This resolves the original
linting issue and (presumably) makes our intent clearer.

refs GH-106
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working linting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant