mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 05:40:11 +01:00
Fix potential leak of HTTP response body in downloadJSON of csaf_aggregator (#618)
This commit is contained in:
parent
900dcede46
commit
ec0c3f9c2c
1 changed files with 7 additions and 5 deletions
|
|
@ -10,6 +10,7 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -20,13 +21,14 @@ var errNotFound = errors.New("not found")
|
|||
|
||||
func downloadJSON(c util.Client, url string, found func(io.Reader) error) error {
|
||||
res, err := c.Get(url)
|
||||
if err != nil || res.StatusCode != http.StatusOK ||
|
||||
if err != nil {
|
||||
return fmt.Errorf("not found: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK ||
|
||||
res.Header.Get("Content-Type") != "application/json" {
|
||||
// ignore this as it is expected.
|
||||
return errNotFound
|
||||
}
|
||||
return func() error {
|
||||
defer res.Body.Close()
|
||||
return found(res.Body)
|
||||
}()
|
||||
return found(res.Body)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue