antoniodipinto / ikisocket

🧬 WebSocket wrapper with event management for Fiber https://github.com/gofiber/fiber. Based on Fiber WebSocket and inspired by Socket.io
MIT License
123 stars 21 forks source link

BUG #14

Closed onekung closed 3 years ago

onekung commented 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) }

antoniodipinto commented 3 years ago

Hi @onekung thank you! Since you provided also the solution, you can create a PR with your code and I will approve it

antoniodipinto commented 3 years ago

Added attribute checking. Thanks for the issue @onekung