Skip to content

Commit

Permalink
client: fix nil check
Browse files Browse the repository at this point in the history
These nil checks were checking an http.Response's Body member instead of
the Response pointer, causing panics whenever the Response pointer was
nil.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Sep 23, 2020
1 parent bc4c324 commit 32b327f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions httptransport/client/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *HTTP) AffectedManifests(ctx context.Context, v []claircore.Vulnerabilit
return affected, fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if resp.Body != nil {
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
Expand Down Expand Up @@ -73,7 +73,7 @@ func (s *HTTP) Index(ctx context.Context, manifest *claircore.Manifest) (*clairc
return nil, fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if resp.Body != nil {
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *HTTP) IndexReport(ctx context.Context, manifest claircore.Digest) (*cla
return nil, false, fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if resp.Body != nil {
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *HTTP) State(ctx context.Context) (string, error) {
return "", fmt.Errorf("failed to create request: %v", err)
}
resp, err := s.c.Do(req)
if resp.Body != nil {
if resp != nil {
defer resp.Body.Close()
}

Expand Down
2 changes: 1 addition & 1 deletion httptransport/client/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *HTTP) Scan(ctx context.Context, ir *claircore.IndexReport) (*claircore.
}

resp, err := c.c.Do(req)
if resp.Body != nil {
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
Expand Down

0 comments on commit 32b327f

Please sign in to comment.