Skip to content

Commit

Permalink
go/sgx/http: close response body on non-200 requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Nov 23, 2023
1 parent 2efdfe2 commit 0817bd8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions go/common/sgx/pcs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (hc *httpClient) doPCSRequest(ctx context.Context, u *url.URL, method, body
"method", method,
"url", u,
)
resp.Body.Close()
return nil, fmt.Errorf("pcs: response status error: %s", http.StatusText(resp.StatusCode))
}

Expand Down
8 changes: 2 additions & 6 deletions go/ias/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (e *httpEndpoint) doIASRequest(ctx context.Context, method, uPath, bodyType
}
if resp.StatusCode != http.StatusOK {
logger.Error("ias response status error", "status", http.StatusText(resp.StatusCode), "method", method, "url", u)
resp.Body.Close()
return nil, fmt.Errorf("ias: response status error: %s", http.StatusText(resp.StatusCode))
}

Expand Down Expand Up @@ -126,9 +127,6 @@ func (e *httpEndpoint) VerifyEvidence(ctx context.Context, evidence *api.Evidenc
query = []string{iasAPIAVRTCBUpdateParam, iasAPIAVRTCBUpdateValueEarly}
}
resp, err := e.doIASRequest(ctx, http.MethodPost, iasAPIAttestationReportPath, "application/json", bytes.NewReader(reqPayload), query...)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return nil, fmt.Errorf("ias: http POST failed: %w", err)
}
Expand Down Expand Up @@ -165,12 +163,10 @@ func (e *httpEndpoint) GetSigRL(ctx context.Context, epidGID uint32) ([]byte, er
// Dispatch the request via HTTP.
p := path.Join(iasAPISigRLPath, hex.EncodeToString(gid[:]))
resp, err := e.doIASRequest(ctx, http.MethodGet, p, "", nil)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return nil, fmt.Errorf("ias: http GET failed: %w", err)
}
defer resp.Body.Close()

// Extract and parse the SigRL.
sigRL, err := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 0817bd8

Please sign in to comment.