Skip to content

Commit 84b1ac3

Browse files
committed
Enable excluded lint checks
There are a set of lint checks that are disabled by default with golangci-lint. This enables them by setting exclude-use-default to false. This by itself triggers a set of lint failures due to these additional checks. To by systematic about addressing these potential issues, this adds those checks back as individual exclusions so they can be addressed on by one. This eliminates one of those individual checks by addressing cases of "Potential file inclusion via variable" where passed in variables are used in os.OpenFile calls. Signed-off-by: Sean McGinnis <[email protected]>
1 parent 799da05 commit 84b1ac3

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

.golangci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ linters:
3838
issues:
3939
max-same-issues: 0
4040
max-issues-per-linter: 0
41+
exclude-use-default: false
4142
# List of regexps of issue texts to exclude, empty list by default.
4243
exclude:
4344
- Using the variable on range scope `(tc)|(rt)|(tt)|(test)|(testcase)|(testCase)` in function literal
4445
- "G108: Profiling endpoint is automatically exposed on /debug/pprof"
46+
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
47+
- (comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form)
48+
- Subprocess launch(ed with variable|ing should be audited)
49+
- (G104|G307)
50+
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
51+
- package comment should be of the form "Package (.+) ..."
4552

4653
run:
4754
timeout: 10m

test/framework/alltypes_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func dumpObject(resource runtime.Object, logPath string) {
138138
namespace := metaObj.GetNamespace()
139139
name := metaObj.GetName()
140140

141-
resourceFilePath := path.Join(logPath, namespace, kind, name+".yaml")
141+
resourceFilePath := filepath.Clean(path.Join(logPath, namespace, kind, name+".yaml"))
142142
Expect(os.MkdirAll(filepath.Dir(resourceFilePath), 0755)).To(Succeed(), "Failed to create folder %s", filepath.Dir(resourceFilePath))
143143

144144
f, err := os.OpenFile(resourceFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

test/framework/bootstrap/kind_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func save(ctx context.Context, image, dest string) error {
152152
// copied from kind https://github.com/kubernetes-sigs/kind/blob/v0.7.0/pkg/cmd/kind/load/docker-image/docker-image.go#L158
153153
// loads an image tarball onto a node.
154154
func load(imageTarName string, node kindnodes.Node) error {
155-
f, err := os.Open(imageTarName)
155+
f, err := os.Open(filepath.Clean(imageTarName))
156156
if err != nil {
157157
return errors.Wrap(err, "failed to open image")
158158
}

test/framework/deployment_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func WatchDeploymentLogs(ctx context.Context, input WatchDeploymentLogsInput) {
120120
go func(pod corev1.Pod, container corev1.Container) {
121121
defer GinkgoRecover()
122122

123-
logFile := path.Join(input.LogPath, input.Deployment.Name, pod.Name, container.Name+".log")
123+
logFile := filepath.Clean(path.Join(input.LogPath, input.Deployment.Name, pod.Name, container.Name+".log"))
124124
Expect(os.MkdirAll(filepath.Dir(logFile), 0755)).To(Succeed())
125125

126126
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

test/framework/kubetest/setup.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import (
2020
"io"
2121
"os"
2222
"path"
23+
"path/filepath"
2324
)
2425

2526
func copyFile(srcFilePath, destFilePath string) error {
2627
err := os.MkdirAll(path.Dir(destFilePath), 0o750)
2728
if err != nil {
2829
return err
2930
}
30-
srcFile, err := os.Open(srcFilePath)
31+
srcFile, err := os.Open(filepath.Clean(srcFilePath))
3132
if err != nil {
3233
return err
3334
}

test/framework/namespace_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func WatchNamespaceEvents(ctx context.Context, input WatchNamespaceEventsInput)
129129
Expect(input.ClientSet).NotTo(BeNil(), "input.ClientSet is required for WatchNamespaceEvents")
130130
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for WatchNamespaceEvents")
131131

132-
logFile := path.Join(input.LogFolder, "resources", input.Name, "events.log")
132+
logFile := filepath.Clean(path.Join(input.LogFolder, "resources", input.Name, "events.log"))
133133
Expect(os.MkdirAll(filepath.Dir(logFile), 0755)).To(Succeed())
134134

135135
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

test/infrastructure/docker/docker/machine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (m *Machine) PreloadLoadImages(ctx context.Context, images []string) error
259259
defer os.RemoveAll(dir)
260260

261261
for i, image := range images {
262-
imageTarPath := filepath.Join(dir, fmt.Sprintf("image-%d.tar", i))
262+
imageTarPath := filepath.Clean(filepath.Join(dir, fmt.Sprintf("image-%d.tar", i)))
263263

264264
err = exec.Command("docker", "save", "-o", imageTarPath, image).Run()
265265
if err != nil {

0 commit comments

Comments
 (0)