Skip to content

Commit 1244d96

Browse files
Copilotaooohan
andauthored
fix: nil pointer dereference when CheckSumItem is absent (#599)
* Initial plan * Fix nil pointer dereference when installing packages without checksums Co-authored-by: aooohan <40265686+aooohan@users.noreply.github.com> * Fix complete with tests and validation Co-authored-by: aooohan <40265686+aooohan@users.noreply.github.com> * Remove accidentally committed binary and update gitignore Co-authored-by: aooohan <40265686+aooohan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: aooohan <40265686+aooohan@users.noreply.github.com>
1 parent 8026607 commit 1244d96

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ coverage.out
99
**/available.cache
1010
**/.available.cache
1111

12-
.vfox
12+
.vfox/vfox

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ go 1.24.0
55
require (
66
atomicgo.dev/cursor v0.2.0
77
atomicgo.dev/keyboard v0.2.9
8+
github.com/BurntSushi/toml v1.6.0
9+
github.com/Microsoft/go-winio v0.6.2
810
github.com/PuerkitoBio/goquery v1.9.3
911
github.com/bodgit/sevenzip v1.5.1
1012
github.com/lithammer/fuzzysearch v1.1.8
@@ -15,15 +17,14 @@ require (
1517
github.com/urfave/cli/v3 v3.4.1
1618
github.com/yuin/gopher-lua v1.1.1
1719
golang.org/x/crypto v0.35.0
20+
golang.org/x/sync v0.19.0
1821
golang.org/x/sys v0.30.0
1922
golang.org/x/term v0.29.0
2023
gopkg.in/yaml.v3 v3.0.1
2124
)
2225

2326
require (
2427
atomicgo.dev/schedule v0.1.0 // indirect
25-
github.com/BurntSushi/toml v1.6.0 // indirect
26-
github.com/Microsoft/go-winio v0.6.2 // indirect
2728
github.com/andybalholm/brotli v1.1.0 // indirect
2829
github.com/andybalholm/cascadia v1.3.2 // indirect
2930
github.com/bodgit/plumbing v1.3.0 // indirect
@@ -48,6 +49,5 @@ require (
4849
github.com/yusufpapurcu/wmi v1.2.4 // indirect
4950
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
5051
golang.org/x/net v0.29.0 // indirect
51-
golang.org/x/sync v0.19.0 // indirect
5252
golang.org/x/text v0.22.0 // indirect
5353
)

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
267267
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
268268
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
269269
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
270-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
271-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
272270
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
273271
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
274272
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

internal/plugin/model.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func (p *PreInstallPackageItem) Label() string {
3636
return p.Name + "@" + p.Version
3737
}
3838

39+
// Checksum returns the checksum for this package, or NoneChecksum if no checksum is provided
40+
func (p *PreInstallPackageItem) Checksum() *shared.Checksum {
41+
if p.CheckSumItem == nil {
42+
return shared.NoneChecksum
43+
}
44+
return p.CheckSumItem.Checksum()
45+
}
46+
3947
type CheckSumItem struct {
4048
Sha256 string `json:"sha256"`
4149
Sha512 string `json:"sha512"`

internal/plugin/model_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package plugin
2+
3+
import (
4+
"testing"
5+
6+
"github.com/version-fox/vfox/internal/shared"
7+
)
8+
9+
func TestPreInstallPackageItem_Checksum(t *testing.T) {
10+
t.Run("Returns NoneChecksum when CheckSumItem is nil", func(t *testing.T) {
11+
// This is the case that was causing the nil pointer dereference
12+
item := &PreInstallPackageItem{
13+
Name: "test-sdk",
14+
Version: "1.0.0",
15+
Path: "https://example.com/test.tar.gz",
16+
CheckSumItem: nil, // Explicitly nil
17+
}
18+
19+
checksum := item.Checksum()
20+
21+
if checksum != shared.NoneChecksum {
22+
t.Errorf("Expected NoneChecksum, got %v", checksum)
23+
}
24+
25+
if checksum.Type != "none" {
26+
t.Errorf("Expected checksum type 'none', got '%s'", checksum.Type)
27+
}
28+
29+
if checksum.Value != "" {
30+
t.Errorf("Expected empty checksum value, got '%s'", checksum.Value)
31+
}
32+
})
33+
34+
t.Run("Returns checksum when CheckSumItem has sha256", func(t *testing.T) {
35+
item := &PreInstallPackageItem{
36+
Name: "test-sdk",
37+
Version: "1.0.0",
38+
Path: "https://example.com/test.tar.gz",
39+
CheckSumItem: &CheckSumItem{
40+
Sha256: "abc123def456",
41+
},
42+
}
43+
44+
checksum := item.Checksum()
45+
46+
if checksum.Type != "sha256" {
47+
t.Errorf("Expected checksum type 'sha256', got '%s'", checksum.Type)
48+
}
49+
50+
if checksum.Value != "abc123def456" {
51+
t.Errorf("Expected checksum value 'abc123def456', got '%s'", checksum.Value)
52+
}
53+
})
54+
55+
t.Run("Returns checksum when CheckSumItem has md5", func(t *testing.T) {
56+
item := &PreInstallPackageItem{
57+
Name: "test-sdk",
58+
Version: "1.0.0",
59+
Path: "https://example.com/test.tar.gz",
60+
CheckSumItem: &CheckSumItem{
61+
Md5: "xyz789",
62+
},
63+
}
64+
65+
checksum := item.Checksum()
66+
67+
if checksum.Type != "md5" {
68+
t.Errorf("Expected checksum type 'md5', got '%s'", checksum.Type)
69+
}
70+
71+
if checksum.Value != "xyz789" {
72+
t.Errorf("Expected checksum value 'xyz789', got '%s'", checksum.Value)
73+
}
74+
})
75+
76+
t.Run("Returns NoneChecksum when CheckSumItem has no checksums", func(t *testing.T) {
77+
item := &PreInstallPackageItem{
78+
Name: "test-sdk",
79+
Version: "1.0.0",
80+
Path: "https://example.com/test.tar.gz",
81+
CheckSumItem: &CheckSumItem{
82+
// All fields empty
83+
},
84+
}
85+
86+
checksum := item.Checksum()
87+
88+
if checksum != shared.NoneChecksum {
89+
t.Errorf("Expected NoneChecksum when all checksum fields are empty, got %v", checksum)
90+
}
91+
})
92+
}

0 commit comments

Comments
 (0)