From 8b5c5f108ece4b4d2b167966ca60d3ec7fdd07c7 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 8 Nov 2024 19:03:23 +0400 Subject: [PATCH] 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 (cherry picked from commit a309f6aa57f4d99bbf17d0fef2fab4602e12b067) --- hack/cloud-image-uploader/aws.go | 19 ++++++++++++++----- hack/cloud-image-uploader/go.mod | 1 + hack/cloud-image-uploader/go.sum | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/hack/cloud-image-uploader/aws.go b/hack/cloud-image-uploader/aws.go index 18e5e2c771..593333cb4f 100644 --- a/hack/cloud-image-uploader/aws.go +++ b/hack/cloud-image-uploader/aws.go @@ -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" ) @@ -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) } diff --git a/hack/cloud-image-uploader/go.mod b/hack/cloud-image-uploader/go.mod index 4423d2f741..b8f2e1ab4c 100644 --- a/hack/cloud-image-uploader/go.mod +++ b/hack/cloud-image-uploader/go.mod @@ -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 diff --git a/hack/cloud-image-uploader/go.sum b/hack/cloud-image-uploader/go.sum index 6ff95a7e10..e0464694b7 100644 --- a/hack/cloud-image-uploader/go.sum +++ b/hack/cloud-image-uploader/go.sum @@ -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=