Skip to content

Commit 8b5c5f1

Browse files
committed
chore: fix nil pointer dereference in AWS uploader
NB: it should be rewritten for AWS SDK v2. The Progress is sometimes `nil` apparently. Signed-off-by: Andrey Smirnov <[email protected]> (cherry picked from commit a309f6a)
1 parent fbf85dd commit 8b5c5f1

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: hack/cloud-image-uploader/aws.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/aws/aws-sdk-go/service/s3/s3manager"
1919
"github.com/google/uuid"
2020
"github.com/klauspost/compress/zstd"
21+
"github.com/siderolabs/go-pointer"
2122
"github.com/siderolabs/go-retry/retry"
2223
"golang.org/x/sync/errgroup"
2324
)
@@ -251,15 +252,23 @@ func (au *AWSUploader) registerAMIArch(ctx context.Context, region string, svc *
251252
}
252253

253254
for _, task := range status.ImportSnapshotTasks {
254-
if *task.ImportTaskId == taskID {
255-
if *task.SnapshotTaskDetail.Status == "completed" {
256-
snapshotID = *task.SnapshotTaskDetail.SnapshotId
255+
if task == nil {
256+
continue
257+
}
258+
259+
if pointer.SafeDeref(task.ImportTaskId) == taskID {
260+
if task.SnapshotTaskDetail == nil {
261+
continue
262+
}
263+
264+
if pointer.SafeDeref(task.SnapshotTaskDetail.Status) == "completed" {
265+
snapshotID = pointer.SafeDeref(task.SnapshotTaskDetail.SnapshotId)
257266

258267
return nil
259268
}
260269

261-
if *task.SnapshotTaskDetail.Progress != progress {
262-
progress = *task.SnapshotTaskDetail.Progress
270+
if pointer.SafeDeref(task.SnapshotTaskDetail.Progress) != progress {
271+
progress = pointer.SafeDeref(task.SnapshotTaskDetail.Progress)
263272

264273
log.Printf("aws: import into %s/%s, import snapshot %s%%", region, arch, progress)
265274
}

Diff for: hack/cloud-image-uploader/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/google/uuid v1.6.0
1818
github.com/klauspost/compress v1.17.9
1919
github.com/siderolabs/gen v0.5.0
20+
github.com/siderolabs/go-pointer v1.0.0
2021
github.com/siderolabs/go-retry v0.3.3
2122
github.com/spf13/pflag v1.0.5
2223
golang.org/x/sync v0.8.0

Diff for: hack/cloud-image-uploader/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
143143
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
144144
github.com/siderolabs/gen v0.5.0 h1:Afdjx+zuZDf53eH5DB+E+T2JeCwBXGinV66A6osLgQI=
145145
github.com/siderolabs/gen v0.5.0/go.mod h1:1GUMBNliW98Xeq8GPQeVMYqQE09LFItE8enR3wgMh3Q=
146+
github.com/siderolabs/go-pointer v1.0.0 h1:6TshPKep2doDQJAAtHUuHWXbca8ZfyRySjSBT/4GsMU=
147+
github.com/siderolabs/go-pointer v1.0.0/go.mod h1:HTRFUNYa3R+k0FFKNv11zgkaCLzEkWVzoYZ433P3kHc=
146148
github.com/siderolabs/go-retry v0.3.3 h1:zKV+S1vumtO72E6sYsLlmIdV/G/GcYSBLiEx/c9oCEg=
147149
github.com/siderolabs/go-retry v0.3.3/go.mod h1:Ff/VGc7v7un4uQg3DybgrmOWHEmJ8BzZds/XNn/BqMI=
148150
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

0 commit comments

Comments
 (0)