Skip to content

Commit

Permalink
Fix possible nil pointer deference
Browse files Browse the repository at this point in the history
If err != nil, we'll still read response.Body, which is bad
  • Loading branch information
rys committed Jan 23, 2019
1 parent 21d59f1 commit f9870bd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mbdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ func process() {

response, err := http.PostForm(mbURL, url.Values{"domain": {records[i].Domain}, "password": {records[i].Token}, "command": {command}})

body, _ := ioutil.ReadAll(response.Body)
response.Body.Close()

if err != nil {
log.Println(fmt.Sprintf(mbResponseError, records[i].Host, records[i].Domain, records[i].Record, records[i].TTL, err.Error()))
continue
}

body, _ := ioutil.ReadAll(response.Body)
response.Body.Close()

if response.StatusCode != 200 {
log.Println(fmt.Sprintf(mbResponseError, records[i].Host, records[i].Domain, records[i].Record, records[i].TTL, response.Status))

Expand Down

0 comments on commit f9870bd

Please sign in to comment.