Skip to content

Commit 0e017aa

Browse files
authored
Bump target Go version to 1.20 (exercism#1118)
* Bump minimum Go version to 1.18 This change bumps the minimum Go version to 1.18 to take advantage of a number of fixes to the language, while matching the minimum version for a number of key dependencies which have been moving away from Go 1.15. This change drops support for Go 1.15 in the Exercism CLI. * Bump minimum go version to 1.19 * fix: update build tags to Go 1.18 syntax ``` ~> go1.18.10 fix ./... ``` * Replace calls to deprecated io/ioutil pkg * fix(deps): update module github.com/spf13/viper to v1.15.0 This change bumps spf13/viper to address reported vulnerabilities in yaml.v2 ``` ~> govulncheck -test ./... Scanning your code and 210 packages across 21 dependent modules for known vulnerabilities... Vulnerability #1: GO-2022-0956 Excessive resource consumption in gopkg.in/yaml.v2 More info: https://pkg.go.dev/vuln/GO-2022-0956 Module: gopkg.in/yaml.v2 Found in: gopkg.in/yaml.v2@v2.0.0-20170721122051-25c4ec802a7d Fixed in: gopkg.in/yaml.v2@v2.2.4 Example traces found: #1: cmd/submit.go:129:23: cmd.getExerciseSolutionFiles calls viper.Viper.ReadInConfig, which eventually calls yaml.Unmarshal Vulnerability exercism#2: GO-2021-0061 Denial of service in gopkg.in/yaml.v2 More info: https://pkg.go.dev/vuln/GO-2021-0061 Module: gopkg.in/yaml.v2 Found in: gopkg.in/yaml.v2@v2.0.0-20170721122051-25c4ec802a7d Fixed in: gopkg.in/yaml.v2@v2.2.3 Example traces found: #1: cmd/submit.go:129:23: cmd.getExerciseSolutionFiles calls viper.Viper.ReadInConfig, which eventually calls yaml.Unmarshal Vulnerability exercism#3: GO-2020-0036 Excessive resource consumption in YAML parsing in gopkg.in/yaml.v2 More info: https://pkg.go.dev/vuln/GO-2020-0036 Module: gopkg.in/yaml.v2 Found in: gopkg.in/yaml.v2@v2.0.0-20170721122051-25c4ec802a7d Fixed in: gopkg.in/yaml.v2@v2.2.8 Example traces found: #1: cmd/submit.go:129:23: cmd.getExerciseSolutionFiles calls viper.Viper.ReadInConfig, which eventually calls yaml.Unmarshal ``` * deps: update module github.com/spf13/cobra to v1.7.0 * deps: update module github.com/stretchr/testify to v1.8.4 * workflows/ci.yml: Add multiple Go versions to testing matrix This change officially removes Go 1.15 from the testing matrix and adds the Go versions used for supporting the Exercism CLI. Namely Go 1.19, 1.20, and 1.21.x. * Bump minimum Go version to 1.20 * Bump Go tooling to use 1.20.x for release and testing. ``` Scanning your code and 207 packages across 19 dependent modules for known vulnerabilities... Vulnerability #1: GO-2023-2043 Improper handling of special tags within script contexts in html/template More info: https://pkg.go.dev/vuln/GO-2023-2043 Standard library Found in: html/template@go1.19.8 Fixed in: html/template@go1.21.1 Example traces found: #1: cmd/troubleshoot.go:127:20: cmd.Status.compile calls template.Template.Execute Vulnerability exercism#2: GO-2023-2041 Improper handling of HTML-like comments in script contexts in html/template More info: https://pkg.go.dev/vuln/GO-2023-2041 Standard library Found in: html/template@go1.19.8 Fixed in: html/template@go1.21.1 Example traces found: #1: cmd/troubleshoot.go:127:20: cmd.Status.compile calls template.Template.Execute Vulnerability exercism#3: GO-2023-1987 Large RSA keys can cause high CPU usage in crypto/tls More info: https://pkg.go.dev/vuln/GO-2023-1987 Standard library Found in: crypto/tls@go1.19.8 Fixed in: crypto/tls@go1.21rc4 Example traces found: #1: api/client.go:68:25: api.Client.Do calls http.Client.Do, which eventually calls tls.Conn.HandshakeContext exercism#2: cli/cli.go:199:23: cli.extractBinary calls io.Copy, which eventually calls tls.Conn.Read exercism#3: debug/debug.go:32:14: debug.Printf calls fmt.Fprintf, which calls tls.Conn.Write exercism#4: api/client.go:68:25: api.Client.Do calls http.Client.Do, which eventually calls tls.Dialer.DialContext Vulnerability exercism#4: GO-2023-1878 Insufficient sanitization of Host header in net/http More info: https://pkg.go.dev/vuln/GO-2023-1878 Standard library Found in: net/http@go1.19.8 Fixed in: net/http@go1.20.6 Example traces found: #1: api/client.go:68:25: api.Client.Do calls http.Client.Do exercism#2: cmd/troubleshoot.go:206:32: cmd.apiPing.Call calls http.Client.Get Vulnerability exercism#5: GO-2023-1840 Unsafe behavior in setuid/setgid binaries in runtime More info: https://pkg.go.dev/vuln/GO-2023-1840 Standard library Found in: runtime@go1.19.8 Fixed in: runtime@go1.20.5 Example traces found: #1: debug/debug.go:80:12: debug.DumpResponse calls log.Fatal, which eventually calls runtime.Caller exercism#2: workspace/exercise_metadata.go:39:26: workspace.NewExerciseMetadata calls json.Unmarshal, which eventually calls runtime.Callers exercism#3: workspace/exercise_metadata.go:39:26: workspace.NewExerciseMetadata calls json.Unmarshal, which eventually calls runtime.CallersFrames exercism#4: workspace/exercise_metadata.go:39:26: workspace.NewExerciseMetadata calls json.Unmarshal, which eventually calls runtime.Frames.Next exercism#5: cmd/root.go:39:27: cmd.Execute calls cobra.Command.Execute, which eventually calls runtime.GC exercism#6: workspace/exercise_metadata.go:66:24: workspace.ExerciseMetadata.Write calls json.Marshal, which eventually calls runtime.GOMAXPROCS exercism#7: config/config.go:57:18: config.Dir calls os.Getenv, which eventually calls runtime.GOROOT exercism#8: cli/cli.go:202:29: cli.extractBinary calls os.File.Seek, which eventually calls runtime.KeepAlive exercism#9: cli/cli.go:135:2: cli.CLI.Upgrade calls os.File.Close, which eventually calls runtime.SetFinalizer exercism#10: debug/debug.go:32:14: debug.Printf calls fmt.Fprintf, which eventually calls runtime.Stack exercism#11: cmd/root.go:39:27: cmd.Execute calls cobra.Command.Execute, which eventually calls runtime.TypeAssertionError.Error exercism#12: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which calls runtime.defaultMemProfileRate exercism#13: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which calls runtime.efaceOf exercism#14: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which eventually calls runtime.findfunc exercism#15: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which calls runtime.float64frombits exercism#16: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which eventually calls runtime.forcegchelper exercism#17: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which eventually calls runtime.funcMaxSPDelta exercism#18: cmd/root.go:39:27: cmd.Execute calls cobra.Command.Execute, which eventually calls runtime.plainError.Error exercism#19: workspace/test_configurations.go:5:2: workspace.init calls runtime.init, which eventually calls runtime.throw Vulnerability exercism#6: GO-2023-1753 Improper handling of empty HTML attributes in html/template More info: https://pkg.go.dev/vuln/GO-2023-1753 Standard library Found in: html/template@go1.19.8 Fixed in: html/template@go1.20.4 Example traces found: #1: cmd/troubleshoot.go:127:20: cmd.Status.compile calls template.Template.Execute Vulnerability exercism#7: GO-2023-1752 Improper handling of JavaScript whitespace in html/template More info: https://pkg.go.dev/vuln/GO-2023-1752 Standard library Found in: html/template@go1.19.8 Fixed in: html/template@go1.20.4 Example traces found: #1: cmd/troubleshoot.go:127:20: cmd.Status.compile calls template.Template.Execute Vulnerability exercism#8: GO-2023-1751 Improper sanitization of CSS values in html/template More info: https://pkg.go.dev/vuln/GO-2023-1751 Standard library Found in: html/template@go1.19.8 Fixed in: html/template@go1.20.4 Example traces found: #1: cmd/troubleshoot.go:127:20: cmd.Status.compile calls template.Template.Execute ```
1 parent 8f2c7ca commit 0e017aa

28 files changed

Lines changed: 620 additions & 185 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
go-version: ["1.15"]
20+
go-version:
21+
- '1.20.x'
22+
- '1.21.x'
2123
os: [ubuntu-latest, windows-latest, macOS-latest]
2224

2325
steps:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Set up Go
2323
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
2424
with:
25-
go-version: '1.19'
25+
go-version: '1.20.x'
2626

2727
- name: Import GPG Key
2828
id: import_gpg

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Exercism would be impossible without people like you being willing to spend time
88

99
## Dependencies
1010

11-
You'll need Go version 1.11 or higher. Follow the directions on http://golang.org/doc/install
11+
You'll need Go version 1.20 or higher. Follow the directions on http://golang.org/doc/install
1212

1313
## Development
1414

api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package api
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
"os"
66

77
"golang.org/x/net/html/charset"
88
"golang.org/x/text/transform"
@@ -17,7 +17,7 @@ var (
1717
)
1818

1919
func readFileAsUTF8String(filename string) (*string, error) {
20-
b, err := ioutil.ReadFile(filename)
20+
b, err := os.ReadFile(filename)
2121
if err != nil {
2222
return nil, err
2323
}

cli/asset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package cli
33
import (
44
"bytes"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
)
99

@@ -28,7 +28,7 @@ func (a *Asset) download() (*bytes.Reader, error) {
2828
}
2929
defer res.Body.Close()
3030

31-
bs, err := ioutil.ReadAll(res.Body)
31+
bs, err := io.ReadAll(res.Body)
3232
if err != nil {
3333
return nil, err
3434
}

cli/cli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/ioutil"
1211
"net/http"
12+
"os"
1313
"runtime"
1414
"strings"
1515
"time"
@@ -161,8 +161,8 @@ func (c *CLI) fetchLatestRelease() error {
161161
return nil
162162
}
163163

164-
func extractBinary(source *bytes.Reader, os string) (binary io.ReadCloser, err error) {
165-
if os == "windows" {
164+
func extractBinary(source *bytes.Reader, platform string) (binary io.ReadCloser, err error) {
165+
if platform == "windows" {
166166
zr, err := zip.NewReader(source, int64(source.Len()))
167167
if err != nil {
168168
return nil, err
@@ -191,7 +191,7 @@ func extractBinary(source *bytes.Reader, os string) (binary io.ReadCloser, err e
191191
if err != nil {
192192
return nil, err
193193
}
194-
tmpfile, err := ioutil.TempFile("", "temp-exercism")
194+
tmpfile, err := os.CreateTemp("", "temp-exercism")
195195
if err != nil {
196196
return nil, err
197197
}

cmd/cmd_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"io"
5-
"io/ioutil"
65
"os"
76
"testing"
87

@@ -63,7 +62,7 @@ type CommandTest struct {
6362
// The method takes a *testing.T as an argument, that way the method can
6463
// fail the test if the creation of the temporary directory fails.
6564
func (test *CommandTest) Setup(t *testing.T) {
66-
dir, err := ioutil.TempDir("", "command-test")
65+
dir, err := os.MkdirTemp("", "command-test")
6766
defer os.RemoveAll(dir)
6867
assert.NoError(t, err)
6968

@@ -104,8 +103,8 @@ func newCapturedOutput() capturedOutput {
104103
return capturedOutput{
105104
oldOut: Out,
106105
oldErr: Err,
107-
newOut: ioutil.Discard,
108-
newErr: ioutil.Discard,
106+
newOut: io.Discard,
107+
newErr: io.Discard,
109108
}
110109
}
111110

cmd/configure_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
//go:build !windows
2-
// +build !windows
32

43
package cmd
54

65
import (
76
"bytes"
8-
"io/ioutil"
97
"net/http"
108
"net/http/httptest"
119
"os"
@@ -344,7 +342,7 @@ func TestConfigureDefaultWorkspaceWithoutClobbering(t *testing.T) {
344342
ts := httptest.NewServer(endpoint)
345343
defer ts.Close()
346344

347-
tmpDir, err := ioutil.TempDir("", "no-clobber")
345+
tmpDir, err := os.MkdirTemp("", "no-clobber")
348346
defer os.RemoveAll(tmpDir)
349347
assert.NoError(t, err)
350348

@@ -379,7 +377,7 @@ func TestConfigureExplicitWorkspaceWithoutClobberingNonDirectory(t *testing.T) {
379377
co.override()
380378
defer co.reset()
381379

382-
tmpDir, err := ioutil.TempDir("", "no-clobber")
380+
tmpDir, err := os.MkdirTemp("", "no-clobber")
383381
defer os.RemoveAll(tmpDir)
384382
assert.NoError(t, err)
385383

@@ -396,7 +394,7 @@ func TestConfigureExplicitWorkspaceWithoutClobberingNonDirectory(t *testing.T) {
396394
}
397395

398396
// Create a file at the workspace directory's location
399-
err = ioutil.WriteFile(filepath.Join(tmpDir, "workspace"), []byte("This is not a directory"), os.FileMode(0755))
397+
err = os.WriteFile(filepath.Join(tmpDir, "workspace"), []byte("This is not a directory"), os.FileMode(0755))
400398
assert.NoError(t, err)
401399

402400
flags := pflag.NewFlagSet("fake", pflag.PanicOnError)

cmd/download.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"errors"
77
"fmt"
88
"io"
9-
"io/ioutil"
109
"net/http"
1110
netURL "net/url"
1211
"os"
@@ -202,8 +201,8 @@ func newDownload(flags *pflag.FlagSet, usrCfg *viper.Viper) (*download, error) {
202201
return nil, decodedAPIError(res)
203202
}
204203

205-
body, _ := ioutil.ReadAll(res.Body)
206-
res.Body = ioutil.NopCloser(bytes.NewReader(body))
204+
body, _ := io.ReadAll(res.Body)
205+
res.Body = io.NopCloser(bytes.NewReader(body))
207206

208207
if err := json.Unmarshal(body, &d.payload); err != nil {
209208
return nil, decodedAPIError(res)

cmd/download_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6-
"io/ioutil"
76
"net/http"
87
"net/http/httptest"
98
"os"
@@ -169,7 +168,7 @@ func TestDownload(t *testing.T) {
169168
}
170169

171170
for _, tc := range testCases {
172-
tmpDir, err := ioutil.TempDir("", "download-cmd")
171+
tmpDir, err := os.MkdirTemp("", "download-cmd")
173172
defer os.RemoveAll(tmpDir)
174173
assert.NoError(t, err)
175174

@@ -197,7 +196,7 @@ func TestDownload(t *testing.T) {
197196
assertDownloadedCorrectFiles(t, targetDir)
198197

199198
dir := filepath.Join(targetDir, "bogus-track", "bogus-exercise")
200-
b, err := ioutil.ReadFile(workspace.NewExerciseFromDir(dir).MetadataFilepath())
199+
b, err := os.ReadFile(workspace.NewExerciseFromDir(dir).MetadataFilepath())
201200
assert.NoError(t, err)
202201
var metadata workspace.ExerciseMetadata
203202
err = json.Unmarshal(b, &metadata)
@@ -229,7 +228,7 @@ func TestDownloadToExistingDirectory(t *testing.T) {
229228
}
230229

231230
for _, tc := range testCases {
232-
tmpDir, err := ioutil.TempDir("", "download-cmd")
231+
tmpDir, err := os.MkdirTemp("", "download-cmd")
233232
defer os.RemoveAll(tmpDir)
234233
assert.NoError(t, err)
235234

@@ -281,7 +280,7 @@ func TestDownloadToExistingDirectoryWithForce(t *testing.T) {
281280
}
282281

283282
for _, tc := range testCases {
284-
tmpDir, err := ioutil.TempDir("", "download-cmd")
283+
tmpDir, err := os.MkdirTemp("", "download-cmd")
285284
defer os.RemoveAll(tmpDir)
286285
assert.NoError(t, err)
287286

@@ -363,7 +362,7 @@ func assertDownloadedCorrectFiles(t *testing.T, targetDir string) {
363362

364363
for _, file := range expectedFiles {
365364
t.Run(file.desc, func(t *testing.T) {
366-
b, err := ioutil.ReadFile(file.path)
365+
b, err := os.ReadFile(file.path)
367366
assert.NoError(t, err)
368367
assert.Equal(t, file.contents, string(b))
369368
})
@@ -383,7 +382,7 @@ func TestDownloadError(t *testing.T) {
383382
ts := httptest.NewServer(handler)
384383
defer ts.Close()
385384

386-
tmpDir, err := ioutil.TempDir("", "submit-err-tmp-dir")
385+
tmpDir, err := os.MkdirTemp("", "submit-err-tmp-dir")
387386
defer os.RemoveAll(tmpDir)
388387
assert.NoError(t, err)
389388

0 commit comments

Comments
 (0)