1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix SEGFAULT if dns resolv error

Per registry.doRequest, res and client might be nil in case of error
For example, dns resolution errors, /etc/docker/certs.d perms, failed
loading of x509 cert ...
This will make res.StatusCode and res.Body SEGFAULT.

Signed-off-by: Arthur Gautier <baloo@gandi.net>
This commit is contained in:
Arthur Gautier 2014-09-03 15:21:06 +02:00
parent b0cff06c97
commit 3e6c69e5a1

View file

@ -153,10 +153,11 @@ func (r *Session) GetRemoteImageJSON(imgID, registry string, token []string) ([]
func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, imgSize int64) (io.ReadCloser, error) { func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, imgSize int64) (io.ReadCloser, error) {
var ( var (
retries = 5 retries = 5
client *http.Client statusCode = 0
res *http.Response client *http.Client
imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID) res *http.Response
imageURL = fmt.Sprintf("%simages/%s/layer", registry, imgID)
) )
req, err := r.reqFactory.NewRequest("GET", imageURL, nil) req, err := r.reqFactory.NewRequest("GET", imageURL, nil)
@ -165,14 +166,19 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, im
} }
setTokenAuth(req, token) setTokenAuth(req, token)
for i := 1; i <= retries; i++ { for i := 1; i <= retries; i++ {
statusCode = 0
res, client, err = r.doRequest(req) res, client, err = r.doRequest(req)
if err != nil { if err != nil {
if res.Body != nil { log.Debugf("Error contacting registry: %s", err)
res.Body.Close() if res != nil {
if res.Body != nil {
res.Body.Close()
}
statusCode = res.StatusCode
} }
if i == retries { if i == retries {
return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)", return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
res.StatusCode, imgID) statusCode, imgID)
} }
time.Sleep(time.Duration(i) * 5 * time.Second) time.Sleep(time.Duration(i) * 5 * time.Second)
continue continue