Skip to content

Commit

Permalink
pubsub/kafkapub: nil pointer dereference
Browse files Browse the repository at this point in the history
`ExampleOpenTopic` (pubsub/kafkapubsub/example_test.go) show a
simple call to `OpenTopic` without `kafkapubsub.TopicOptions` as
passing a `nil` argument.
This is done 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.
  • Loading branch information
danielorbach committed Jan 15, 2023
1 parent 664ae9b commit a5b7e6c
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 a5b7e6c

Please sign in to comment.