Skip to content

Commit d81be53

Browse files
authored
Add gosec of GitHub action (#11)
1 parent 5ba75dd commit d81be53

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

.github/workflows/pull-request.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,29 @@ jobs:
4040
uses: Jerome1337/[email protected]
4141
with:
4242
golint-path: ./...
43+
Security:
44+
name: Security
45+
runs-on: ubuntu-latest
46+
env:
47+
GO111MODULE: on
48+
steps:
49+
- name: Checkout Source
50+
uses: actions/checkout@v2
51+
- name: Run Gosec Security Scanner
52+
uses: securego/gosec@master
53+
with:
54+
args: '-exclude=G402,G204,G304,G110 ./...'
55+
CodeQL:
56+
name: CodeQL
57+
runs-on: ubuntu-latest
58+
env:
59+
GO111MODULE: on
60+
steps:
61+
- name: Checkout Source
62+
uses: actions/checkout@v2
63+
- name: Initialize CodeQL
64+
uses: github/codeql-action/init@v1
65+
with:
66+
languages: go
67+
- name: Perform CodeQL Analysis
68+
uses: github/codeql-action/analyze@v1

cmd/install.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (o *installOption) overWriteBinary(sourceFile, targetPath string) (err erro
6464
}
6565
default:
6666
sourceF, _ := os.Open(sourceFile)
67-
targetF, _ := os.OpenFile(targetPath, os.O_CREATE|os.O_RDWR, 0664)
67+
targetF, _ := os.OpenFile(targetPath, os.O_CREATE|os.O_RDWR, 0600)
6868
if _, err = io.Copy(targetF, sourceF); err != nil {
6969
err = fmt.Errorf("cannot copy %s from %s to %v, error: %v", o.name, sourceFile, targetPath, err)
7070
}
@@ -119,8 +119,8 @@ func (o *installOption) extractFiles(tarFile, targetName string) (err error) {
119119
func execCommand(name string, arg ...string) (err error) {
120120
command := exec.Command(name, arg...)
121121

122-
var stdout []byte
123-
var errStdout error
122+
//var stdout []byte
123+
//var errStdout error
124124
stdoutIn, _ := command.StdoutPipe()
125125
stderrIn, _ := command.StderrPipe()
126126
err = command.Start()
@@ -134,11 +134,11 @@ func execCommand(name string, arg ...string) (err error) {
134134
var wg sync.WaitGroup
135135
wg.Add(1)
136136
go func() {
137-
stdout, errStdout = copyAndCapture(os.Stdout, stdoutIn)
137+
_, _ = copyAndCapture(os.Stdout, stdoutIn)
138138
wg.Done()
139139
}()
140140

141-
copyAndCapture(os.Stderr, stderrIn)
141+
_, _ = copyAndCapture(os.Stderr, stderrIn)
142142

143143
wg.Wait()
144144

pkg/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ func (h *HTTPDownloader) DownloadFile() error {
159159
// Create the file
160160
out, err := os.Create(filepath)
161161
if err != nil {
162+
_ = out.Close()
162163
return err
163164
}
164-
defer out.Close()
165165

166166
writer.Writer = out
167167

@@ -216,7 +216,7 @@ func DownloadFileWithMultipleThreadKeepParts(targetURL, targetFilePath string, t
216216

217217
// concat all these partial files
218218
var f *os.File
219-
if f, err = os.OpenFile(targetFilePath, os.O_CREATE|os.O_WRONLY, 0644); err == nil {
219+
if f, err = os.OpenFile(targetFilePath, os.O_CREATE|os.O_WRONLY, 0600); err == nil {
220220
defer func() {
221221
_ = f.Close()
222222
}()

pkg/progress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ func (i *ProgressIndicator) setBar(n int) {
5252
i.count += float64(n)
5353

5454
if i.bar != nil {
55-
i.bar.Set((int)(i.count * 100 / i.Total))
55+
_ = i.bar.Set((int)(i.count * 100 / i.Total))
5656
}
5757
}

0 commit comments

Comments
 (0)