Closed onekung closed 3 years ago
Describe the bug panic: interface conversion on function GetStringAttribute / GetIntAttribute can't read null memory
To Reproduce
Check kws.attributes map variable before return interface conversion.
func (kws *Websocket) GetIntAttribute(key string) int { kws.mu.RLock() defer kws.mu.RUnlock() val, ok := kws.attributes[key] if !ok || val == nil { return 0 } return val.(int) }
func (kws *Websocket) GetStringAttribute(key string) string { kws.mu.RLock() defer kws.mu.RUnlock() val, ok := kws.attributes[key] if !ok || val == nil { return "" } return val.(string) }
Hi @onekung thank you! Since you provided also the solution, you can create a PR with your code and I will approve it
Added attribute checking. Thanks for the issue @onekung
Describe the bug panic: interface conversion on function GetStringAttribute / GetIntAttribute can't read null memory
To Reproduce
Check kws.attributes map variable before return interface conversion.
func (kws *Websocket) GetIntAttribute(key string) int { kws.mu.RLock() defer kws.mu.RUnlock() val, ok := kws.attributes[key] if !ok || val == nil { return 0 } return val.(int) }
func (kws *Websocket) GetStringAttribute(key string) string { kws.mu.RLock() defer kws.mu.RUnlock() val, ok := kws.attributes[key] if !ok || val == nil { return "" } return val.(string) }