From 9e390b5dc7e8401790972e629dd0248a1b6b5a70 Mon Sep 17 00:00:00 2001 From: Sven Walter Date: Fri, 3 Nov 2017 15:50:14 +0100 Subject: [PATCH] fix another null pointer dereference in S3 --- resources/s3-buckets.go | 2 +- resources/util.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/s3-buckets.go b/resources/s3-buckets.go index 0645f038e..431d2715b 100644 --- a/resources/s3-buckets.go +++ b/resources/s3-buckets.go @@ -25,7 +25,7 @@ func (n *S3Nuke) DescribeBuckets() ([]string, error) { return nil, err } - if *bucketLocationResponse.LocationConstraint == *n.Service.Config.Region { + if EqualStringPtr(bucketLocationResponse.LocationConstraint, n.Service.Config.Region) { buckets = append(buckets, *out.Name) } diff --git a/resources/util.go b/resources/util.go index 143933877..c2651a99d 100644 --- a/resources/util.go +++ b/resources/util.go @@ -8,3 +8,15 @@ import ( func GetCategory(r Resource) string { return strings.Split(fmt.Sprintf("%T", r), ".")[1] // hackey } + +func EqualStringPtr(v1, v2 *string) bool { + if v1 == nil && v2 == nil { + return true + } + + if v1 == nil || v2 == nil { + return false + } + + return *v1 == *v2 +}