Skip to content

Commit

Permalink
chore: fix nil pointer dereference in AWS uploader
Browse files Browse the repository at this point in the history
NB: it should be rewritten for AWS SDK v2.

The Progress is sometimes `nil` apparently.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
(cherry picked from commit a309f6a)
  • Loading branch information
smira committed Nov 13, 2024
1 parent fbf85dd commit 8b5c5f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
19 changes: 14 additions & 5 deletions hack/cloud-image-uploader/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/google/uuid"
"github.com/klauspost/compress/zstd"
"github.com/siderolabs/go-pointer"
"github.com/siderolabs/go-retry/retry"
"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -251,15 +252,23 @@ func (au *AWSUploader) registerAMIArch(ctx context.Context, region string, svc *
}

for _, task := range status.ImportSnapshotTasks {
if *task.ImportTaskId == taskID {
if *task.SnapshotTaskDetail.Status == "completed" {
snapshotID = *task.SnapshotTaskDetail.SnapshotId
if task == nil {
continue
}

if pointer.SafeDeref(task.ImportTaskId) == taskID {
if task.SnapshotTaskDetail == nil {
continue
}

if pointer.SafeDeref(task.SnapshotTaskDetail.Status) == "completed" {
snapshotID = pointer.SafeDeref(task.SnapshotTaskDetail.SnapshotId)

return nil
}

if *task.SnapshotTaskDetail.Progress != progress {
progress = *task.SnapshotTaskDetail.Progress
if pointer.SafeDeref(task.SnapshotTaskDetail.Progress) != progress {
progress = pointer.SafeDeref(task.SnapshotTaskDetail.Progress)

log.Printf("aws: import into %s/%s, import snapshot %s%%", region, arch, progress)
}
Expand Down
1 change: 1 addition & 0 deletions hack/cloud-image-uploader/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/google/uuid v1.6.0
github.com/klauspost/compress v1.17.9
github.com/siderolabs/gen v0.5.0
github.com/siderolabs/go-pointer v1.0.0
github.com/siderolabs/go-retry v0.3.3
github.com/spf13/pflag v1.0.5
golang.org/x/sync v0.8.0
Expand Down
2 changes: 2 additions & 0 deletions hack/cloud-image-uploader/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/siderolabs/gen v0.5.0 h1:Afdjx+zuZDf53eH5DB+E+T2JeCwBXGinV66A6osLgQI=
github.com/siderolabs/gen v0.5.0/go.mod h1:1GUMBNliW98Xeq8GPQeVMYqQE09LFItE8enR3wgMh3Q=
github.com/siderolabs/go-pointer v1.0.0 h1:6TshPKep2doDQJAAtHUuHWXbca8ZfyRySjSBT/4GsMU=
github.com/siderolabs/go-pointer v1.0.0/go.mod h1:HTRFUNYa3R+k0FFKNv11zgkaCLzEkWVzoYZ433P3kHc=
github.com/siderolabs/go-retry v0.3.3 h1:zKV+S1vumtO72E6sYsLlmIdV/G/GcYSBLiEx/c9oCEg=
github.com/siderolabs/go-retry v0.3.3/go.mod h1:Ff/VGc7v7un4uQg3DybgrmOWHEmJ8BzZds/XNn/BqMI=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down

0 comments on commit 8b5c5f1

Please sign in to comment.