Fix the UnboundLocalError when verifying images.
When verifying an image that doesn't hashtree, and without providing
`--accept_zeroed_hashtree`, it hits the following error.
$ avbtool verify_image --image apex_payload.img
Verifying image apex_payload.img using embedded public key
vbmeta: Successfully verified footer and SHA256_RSA4096 vbmeta struct in apex_payload.img
Traceback (most recent call last):
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/internal/stdlib/runpy.py", line 174, in _run_module_as_main
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/internal/stdlib/runpy.py", line 72, in _run_code
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/__main__.py", line 12, in <module>
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/internal/stdlib/runpy.py", line 174, in _run_module_as_main
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/internal/stdlib/runpy.py", line 72, in _run_code
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/avbtool.py", line 4519, in <module>
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/avbtool.py", line 4348, in run
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/avbtool.py", line 4471, in verify_image
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/avbtool.py", line 2368, in verify_image
File "/mnt/aosp/aosp-master/out/soong/host/linux-x86/bin/avbtool/avbtool.py", line 1419, in verify
UnboundLocalError: local variable 'image_filename' referenced before assignment
Test: Run the above command with and without --accept_zeroed_hashtree.
Change-Id: I15a8478b5db1b3bf22dee3246b41a309f070ac9a
diff --git a/avbtool b/avbtool
index ce48155..665c24e 100755
--- a/avbtool
+++ b/avbtool
@@ -1386,6 +1386,7 @@
True if the descriptor verifies, False otherwise.
"""
if self.partition_name == '':
+ image_filename = image_containing_descriptor.filename
image = image_containing_descriptor
else:
image_filename = os.path.join(image_dir, self.partition_name + image_ext)
@@ -1416,7 +1417,7 @@
else:
if hash_tree != hash_tree_ondisk:
sys.stderr.write('hashtree of {} contains invalid data\n'.
- format(image_filename))
+ format(image_filename))
return False
print ('{}: Successfully verified {} hashtree of {} for image of {} bytes'
.format(self.partition_name, self.hash_algorithm, image.filename,
@@ -1549,6 +1550,7 @@
True if the descriptor verifies, False otherwise.
"""
if self.partition_name == '':
+ image_filename = image_containing_descriptor.filename
image = image_containing_descriptor
else:
image_filename = os.path.join(image_dir, self.partition_name + image_ext)