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 <[email protected]>
  • Loading branch information
smira committed Nov 8, 2024
1 parent 333737f commit a309f6a
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.11
github.com/siderolabs/gen v0.7.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 @@ -181,6 +181,8 @@ github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0
github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA=
github.com/siderolabs/gen v0.7.0 h1:uHAt3WD0dof28NHFuguWBbDokaXQraR/HyVxCLw2QCU=
github.com/siderolabs/gen v0.7.0/go.mod h1:an3a2Y53O7kUjnnK8Bfu3gewtvnIOu5RTU6HalFtXQQ=
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 a309f6a

Please sign in to comment.