Skip to content

Commit

Permalink
Fix nil dereference error (Azure#7546)
Browse files Browse the repository at this point in the history
e.Table.tsc.client.exec can return nil resp and non-nil err. This causes
resp.StatusCode to crash with nil dereference. This change adds the
nil check on resp before accessing StatusCode.
  • Loading branch information
ashvindeodhar authored Feb 26, 2020
1 parent 06f1741 commit dee1b8d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions storage/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (e *Entity) Delete(force bool, options *EntityOptions) error {
uri := e.Table.tsc.client.getEndpoint(tableServiceName, e.buildPath(), query)
resp, err := e.Table.tsc.client.exec(http.MethodDelete, uri, headers, nil, e.Table.tsc.auth)
if err != nil {
if resp.StatusCode == http.StatusPreconditionFailed {
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
return fmt.Errorf(etagErrorTemplate, err)
}
return err
Expand Down Expand Up @@ -433,7 +433,7 @@ func (e *Entity) updateMerge(force bool, verb string, options *EntityOptions) er
uri := e.Table.tsc.client.getEndpoint(tableServiceName, e.buildPath(), query)
resp, err := e.Table.tsc.client.exec(verb, uri, headers, bytes.NewReader(body), e.Table.tsc.auth)
if err != nil {
if resp.StatusCode == http.StatusPreconditionFailed {
if resp != nil && resp.StatusCode == http.StatusPreconditionFailed {
return fmt.Errorf(etagErrorTemplate, err)
}
return err
Expand Down

0 comments on commit dee1b8d

Please sign in to comment.