From d823ec54cd5e930cf66c08ce114a2acd57b02e49 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Fri, 19 Aug 2022 12:38:32 +0530 Subject: [PATCH] fix(pubnub-sub): add pubnub validation to prevent memory leak (#8) add pubnub config validation to check for empty subscribe key --- protocols/sub/pubnub.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/protocols/sub/pubnub.go b/protocols/sub/pubnub.go index 97cc665..e02ed48 100644 --- a/protocols/sub/pubnub.go +++ b/protocols/sub/pubnub.go @@ -1,6 +1,7 @@ package sub import ( + "errors" "fmt" "os" @@ -86,6 +87,10 @@ func (sub *PubnubSubscriber) Configure(configs []interface{}) error { if err != nil { return err } + err = validatePubnubConfig(sub.pubnubConfig) + if err != nil { + return err + } sub.pubnubConfig.FileName = strings.Replace(sub.pubnubConfig.Topic, "/", "", -1) if len(configs) == 2 { redisConfig := configs[1].(map[string]interface{}) @@ -98,6 +103,13 @@ func (sub *PubnubSubscriber) Configure(configs []interface{}) error { return err } +func validatePubnubConfig(cfg pubnubConfig) error { + if cfg.SubscribeKey == "" { + return errors.New("Subscribe Key Missing") + } + return nil +} + func (sub *PubnubSubscriber) Close() { sub.connection.Destroy(sub.pubnubConfig.Topic) }