The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/1918

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Before, we always tried to hash the body regardless of the status code,
which meant that we would hash the contents of e.g. a 404 message if the
thing wasn't found, and issue a "Hash mismatch" error, masking the real
error.

Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com>
From 35d21ede265b65d2f4e9e0047b9c716a968b9799 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.ander...@canonical.com>
Date: Thu, 21 Apr 2016 17:02:22 -0600
Subject: [PATCH] simplestreams: give better error on invalid source stream

Before, we always tried to hash the body regardless of the status code,
which meant that we would hash the contents of e.g. a 404 message if the
thing wasn't found, and issue a "Hash mismatch" error, masking the real
error.

Signed-off-by: Tycho Andersen <tycho.ander...@canonical.com>
---
 shared/simplestreams.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/shared/simplestreams.go b/shared/simplestreams.go
index ab2d540..7842e75 100644
--- a/shared/simplestreams.go
+++ b/shared/simplestreams.go
@@ -482,6 +482,10 @@ func (s *SimpleStreams) downloadFile(path string, hash 
string, target string, pr
                }
                defer resp.Body.Close()
 
+               if resp.StatusCode != http.StatusOK {
+                       return fmt.Errorf("invalid simplestreams source: got %d 
looking for %s", resp.StatusCode, path)
+               }
+
                body := &TransferProgress{Reader: resp.Body, Length: 
resp.ContentLength, Handler: progress}
 
                sha256 := sha256.New()
@@ -490,9 +494,10 @@ func (s *SimpleStreams) downloadFile(path string, hash 
string, target string, pr
                        return err
                }
 
-               if fmt.Sprintf("%x", sha256.Sum(nil)) != hash {
+               result := fmt.Sprintf("%x", sha256.Sum(nil))
+               if result != hash {
                        os.Remove(target)
-                       return fmt.Errorf("Hash mismatch")
+                       return fmt.Errorf("Hash mismatch for %s: %s != %s", 
path, result, hash)
                }
 
                return nil
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to