Skip to content

Commit

Permalink
pubsub/kafkapub: nil pointer dereference
Browse files Browse the repository at this point in the history
The [examples][ExampleOpenTopic] show a simple call to `OpenTopic`
without `kafkapubsub.TopicOptions` as passing a `nil` argument.
This is backed by replacing a `nil` pointer with the appropriate
zero-value.  This behaviour exists in `OpenSubscription` too.
However, PR google#3163 introduced overriding batching options which
inadvertently accesses a field of a nil pointer.

[ExampleOpenTopic]: https://github.com/google/go-cloud/blob/master/pubsub/kafkapubsub/example_test.go#L36
  • Loading branch information
danielorbach committed Jan 15, 2023
1 parent 664ae9b commit c0667e7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pubsub/kafkapubsub/kafka.go
Expand Up @@ -234,7 +234,11 @@ func OpenTopic(brokers []string, config *sarama.Config, topicName string, opts *
if err != nil {
return nil, err
}
bo := sendBatcherOpts.NewMergedOptions(&opts.BatcherOptions)
bo := &batcher.Options{}
if opts != nil {
bo = &opts.BatcherOptions
}
bo = sendBatcherOpts.NewMergedOptions(bo)
return pubsub.NewTopic(dt, bo), nil
}

Expand Down

0 comments on commit c0667e7

Please sign in to comment.