twilio / twilio-go

A Go package for communicating with the Twilio API.
MIT License
290 stars 40 forks source link

panic occurs when fetching messaging service for SID with trailing whitespace #193

Closed apobletts closed 1 year ago

apobletts commented 1 year ago

Issue Summary

I use the following code to check if a messaging service is valid

_, err = twilioClient.MessagingV1.FetchService(p.TwilioConfig.MessagingServiceSid)
if err != nil {
  // handle error
}

If the MessageService SID contains trailing whitespace, then the library produces a panic.

Steps to Reproduce

  1. Create a Twilio Client
  2. Fetch Messaging Service with Messaging Service SID that has trailing whitespace

Code Snippet

_, err = twilioClient.MessagingV1.FetchService("MSabc123\t")
if err != nil {
  // handle error
}

Exception/Log

2022/10/13 15:15:12 http: panic serving 172.24.0.1:57074: runtime error: invalid memory address or nil pointer dereference
goroutine 69 [running]:
net/http.(*conn).serve.func1()
       /usr/local/go/src/net/http/server.go:1825 +0xbf
panic({0x113d760, 0x1ccfd00})
github.com/twilio/twilio-go/client.(*RequestHandler).BuildUrl(0xc00081b620, {0xc000098000?, 0xc000556e18?})
       /go/pkg/mod/github.com/twilio/twilio-go@v0.18.2/client/request_handler.go:37 +0x4a
github.com/twilio/twilio-go/client.(*RequestHandler).sendRequest(0xc00081b620, {0x130c879, 0x3}, {0xc000098000?, 0xc000120450?}, 0x23?, 0xffffffffffffffff?)
       /go/pkg/mod/github.com/twilio/twilio-go@v0.18.2/client/request_handler.go:27 +0x3d
github.com/twilio/twilio-go/client.(*RequestHandler).Get(...)
       /go/pkg/mod/github.com/twilio/twilio-go@v0.18.2/client/request_handler.go:83
github.com/twilio/twilio-go/rest/messaging/v1.(*ApiService).FetchService(0xc00051c2a0, {0xc000120450?, 0xc000556f78?})
       /go/pkg/mod/github.com/twilio/twilio-go@v0.18.2/rest/messaging/v1/services.go:219 +0xfc

Technical details:

beebzz commented 1 year ago

Hi @apobletts, thanks for submitting an issue. I'm unable to reproduce this using the latest version of twilio-go (1.0.0). Have you tried upgrading to 1.0.0 then seeing if the whitespaces break the request?

apobletts commented 1 year ago

Hi @beebzz . It does looks like I can only reproduce in 0.18.2, but not in 1.0.0. I will upgrade. Thank you!