[elbe-devel] [PATCH] hashes: fix error path on download failure
Goldschmidt Simon
sgoldschmidt at de.pepperl-fuchs.com
Wed Nov 14 09:38:56 CET 2018
HashValidator.download_and_validate_file() accesses an uninitialized
local variable when urlopen() fails ('rf.close()').
To fix this, initialize 'rf' to None and only call 'rf.close()' if it
is != None.
Signed-off-by: Simon Goldschmidt <sgoldschmidt at de.pepperl-fuchs.com>
---
elbepack/hashes.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/elbepack/hashes.py b/elbepack/hashes.py
index 47482790..d2dfe053 100644
--- a/elbepack/hashes.py
+++ b/elbepack/hashes.py
@@ -57,11 +57,13 @@ class HashValidator(object):
def download_and_validate_file(self, upstream_fname, local_fname):
url = self.base_url + upstream_fname
+ rf = None
try:
rf = urlopen(url, None, 10)
with open(local_fname, "w") as wf:
copyfileobj(rf, wf)
finally:
- rf.close()
+ if rf is not None:
+ rf.close()
self.validate_file(upstream_fname, local_fname)
--
2.17.0.windows.1
More information about the elbe-devel
mailing list