[elbe-devel] [PATCH] hashes: fix error path on download failure

Manuel Traut manut at linutronix.de
Thu Nov 15 12:24:03 CET 2018


Hi Simon,

On Wed, Nov 14, 2018 at 08:38:56AM +0000, Goldschmidt Simon wrote:
> 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>

Reviewed-by: Manuel Traut <manut at linutronix.de>

thanks for your 1st contribution to elbe!

I applied your fix to devel/elbe-3.0 and it will be part of the next
elbe-testing release!

Regards,
  Manuel

> ---
>  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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel



More information about the elbe-devel mailing list