Skip to content

[BUG] contrib/aws/aws-sdk-go-v2/aws: Setting targetArn instead of topicArn leads to nil pointer dereference #2001

Description

@j-sv

Version of dd-trace-go
Using v1.51.0.

Describe what happened:
Using the AWS middleware for SDK v2 and publishing an SNS message using targetArn to set the topic leads to a nil dereference here.

Describe what you expected:
That the SNS message is published successfully.

Steps to reproduce the issue:
This is run with LocalStack.

package main

import (
	"context"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sns"
	awstrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws"
)

func main() {
	ctx := context.Background()

	resolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...any) (aws.Endpoint, error) {
		return aws.Endpoint{
			PartitionID:   "aws",
			URL:           "http://localhost:4566",
			SigningRegion: "eu-west-1",
		}, nil
	})

	c, err := config.LoadDefaultConfig(
		ctx,
		config.WithEndpointResolverWithOptions(resolver),
		config.WithCredentialsProvider(aws.CredentialsProviderFunc(
			func(_ context.Context) (aws.Credentials, error) {
				return aws.Credentials{
					AccessKeyID:     "0",
					SecretAccessKey: "0",
				}, nil
			},
		)),
	)
	if err != nil {
		panic(err)
	}

	awstrace.AppendMiddleware(&c)

	client := sns.NewFromConfig(c)

	client.Publish(ctx, &sns.PublishInput{
		TargetArn: aws.String("foo"),
		Message:   aws.String("Hello, world!"),
	})
}
$ go run main.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8c45df]

goroutine 1 [running]:
gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws.topicName({{0x927ec0?, 0xc000095770?}})
        /x/go/pkg/mod/gopkg.in/!data!dog/[email protected]/contrib/aws/aws-sdk-go-v2/aws/aws.go:200 +0x19f
gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws.resourceNameFromParams({{0x927ec0?, 0xc000095770?}}, {0x9c7ebb?, 0xdfb230?})
        /x/go/pkg/mod/gopkg.in/!data!dog/[email protected]/contrib/aws/aws-sdk-go-v2/aws/aws.go:144 +0x1ae
gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws.(*traceMiddleware).startTraceMiddleware.func1({0xa8d9d8, 0xc00021bf80}, {{0x927ec0?, 0xc000095770?}}, {0xa8a240, 0xc0001ef4c0})
        /x/go/pkg/mod/gopkg.in/!data!dog/[email protected]/contrib/aws/aws-sdk-go-v2/aws/aws.go:116 +0x81d
github.com/aws/smithy-go/middleware.initializeMiddlewareFunc.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:67
github.com/aws/smithy-go/middleware.decoratedInitializeHandler.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:200
github.com/aws/aws-sdk-go-v2/service/sns.(*validateOpPublish).HandleInitialize(0x496f86?, {0xa8d9d8, 0xc00021bf80}, {{0x927ec0?, 0xc000095770?}}, {0xa8a1c0, 0xc00021f120})
        /x/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/[email protected]/validators.go:450 +0xcb
github.com/aws/smithy-go/middleware.decoratedInitializeHandler.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:200
github.com/aws/smithy-go/middleware.(*setLogger).HandleInitialize(0x6bcdfe?, {0xa8d9d8?, 0xc00021bf50?}, {{0x927ec0?, 0xc000095770?}}, {0xa8a1c0, 0xc00021f140})
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/logging.go:45 +0x95
github.com/aws/smithy-go/middleware.decoratedInitializeHandler.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:200
github.com/aws/aws-sdk-go-v2/aws/middleware.RegisterServiceMetadata.HandleInitialize({{0x9c7ebb, 0x3}, {0x9c7fd5, 0x3}, {0x0, 0x0}, {0x9c9341, 0x7}}, {0xa8d9d8, 0xc00021be30}, ...)
        /x/go/pkg/mod/github.com/aws/[email protected]/aws/middleware/metadata.go:40 +0x1d1
github.com/aws/smithy-go/middleware.decoratedInitializeHandler.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:200
gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go-v2/aws.(*traceMiddleware).initTraceMiddleware.func1({0xa8d9d8, 0xc00021bcb0}, {{0x927ec0?, 0xc000095770?}}, {0xa8a1c0, 0xc00021f180})
        /x/go/pkg/mod/gopkg.in/!data!dog/[email protected]/contrib/aws/aws-sdk-go-v2/aws/aws.go:90 +0xc5
github.com/aws/smithy-go/middleware.initializeMiddlewareFunc.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:67
github.com/aws/smithy-go/middleware.decoratedInitializeHandler.HandleInitialize(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:200
github.com/aws/smithy-go/middleware.(*InitializeStep).HandleMiddleware(0xc0001c9330?, {0xa8d9d8, 0xc00021bcb0}, {0x927ec0, 0xc000095770}, {0xa8a1a0, 0xc00021f0e0})
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/step_initialize.go:114 +0x22f
github.com/aws/smithy-go/middleware.decoratedHandler.Handle(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/middleware.go:57
github.com/aws/smithy-go/middleware.(*Stack).HandleMiddleware(0xc0001c9428?, {0xa8d9d8, 0xc00021bcb0}, {0x927ec0, 0xc000095770}, {0xa8a280?, 0xc0001ef4b0?})
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/stack.go:109 +0x17b
github.com/aws/smithy-go/middleware.decoratedHandler.Handle(...)
        /x/go/pkg/mod/github.com/aws/[email protected]/middleware/middleware.go:57
github.com/aws/aws-sdk-go-v2/service/sns.(*Client).invokeOperation(0xc000215900, {0xa8d968?, 0xc000028110?}, {0x9c9341, 0x7}, {0x927ec0, 0xc000095770}, {0x0, 0x0, 0x0}, ...)
        /x/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/[email protected]/api_client.go:187 +0x642
github.com/aws/aws-sdk-go-v2/service/sns.(*Client).Publish(0x0?, {0xa8d968?, 0xc000028110?}, 0xc000212b40?, {0x0?, 0x0?, 0x0?})
        /x/go/pkg/mod/github.com/aws/aws-sdk-go-v2/service/[email protected]/api_op_Publish.go:33 +0x127
main.main()
        /tmp/tmp.XX92oopTfo/main.go:43 +0x2d5
exit status 2

Additional environment details (Version of Go, Operating System, etc.):
Go version go1.20.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apm:ecosystemcontrib/* related feature requests or bugsbugunintended behavior that has to be fixed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions