Skip to content

Commit 1e78804

Browse files
authored
fix(hook/gomod): check if gosum is nil (fanal#487)
1 parent ca57d31 commit 1e78804

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

hook/gomod/gomod.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ func (h gomodMergeHook) Hook(blob *types.BlobInfo) error {
3232
if file == types.GoMod && lessThanGo117(app) {
3333
// e.g. /app/go.mod => /app/go.sum
3434
gosumFile := filepath.Join(dir, types.GoSum)
35-
gosum := findGoSum(gosumFile, blob.Applications)
36-
mergeGoSum(&app, gosum)
35+
if gosum := findGoSum(gosumFile, blob.Applications); gosum != nil {
36+
mergeGoSum(&app, gosum)
37+
}
3738
}
3839
}
3940
apps = append(apps, app)

hook/gomod/gomod_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,45 @@ func Test_gomodMergeHook_Hook(t *testing.T) {
154154
},
155155
},
156156
},
157+
{
158+
name: "Go 1.16 and go.sum is not found",
159+
blob: &types.BlobInfo{
160+
Applications: []types.Application{
161+
{
162+
Type: types.GoModule,
163+
FilePath: "/app/go.mod",
164+
Libraries: []types.Package{
165+
{
166+
Name: "github.com/aquasecurity/go-dep-parser",
167+
Version: "v0.0.0-20220412145205-d0501f906d90",
168+
},
169+
{
170+
Name: "github.com/aws/aws-sdk-go",
171+
Version: "v1.43.31",
172+
},
173+
},
174+
},
175+
},
176+
},
177+
want: &types.BlobInfo{
178+
Applications: []types.Application{
179+
{
180+
Type: types.GoModule,
181+
FilePath: "/app/go.mod",
182+
Libraries: []types.Package{
183+
{
184+
Name: "github.com/aquasecurity/go-dep-parser",
185+
Version: "v0.0.0-20220412145205-d0501f906d90",
186+
},
187+
{
188+
Name: "github.com/aws/aws-sdk-go",
189+
Version: "v1.43.31",
190+
},
191+
},
192+
},
193+
},
194+
},
195+
},
157196
}
158197
for _, tt := range tests {
159198
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)