XeroAPI / xerogolang

Golang SDK for the Xero API
MIT License
24 stars 29 forks source link

Variable shadowing bug. #12

Closed nsf closed 6 years ago

nsf commented 6 years ago

There is a bug in this chunk of code:

https://github.com/XeroAPI/xerogolang/blob/master/xerogolang.go#L228-L246

On line 233 a new err variable is declared. Hence on line 239 the result of client.Do is assigned to inner scope err and outer scope response. Which means err is never checked there for being nil and it's possible that in outer scope you'll see both response and err being nil. Which in turn leads to nil dereference on line 252.

The fix would be to replace line 233 with:

client, _ := p.consumer.MakeHttpClient(sess.AccessToken)

Well at least right now oauth consumer's MakeHttpClient never returns an error, so it's pointless to check it there.

TheRegan commented 6 years ago

Good catch! I've made the proposed changes :-)