aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@kernel.crashing.org>2022-10-06 16:53:22 -0500
committerSteve Sakoman <steve@sakoman.com>2023-02-10 09:34:38 -1000
commitd26ed38c233583b35ad1451e521f07d9c2329f4e (patch)
tree14218ac93ae869d62677ebb5eebb5aa0cf9fe040
parent590ae6fde9da75db3a368e5c0d47920696c33ebf (diff)
downloadbitbake-d26ed38c233583b35ad1451e521f07d9c2329f4e.tar.gz
utils/ply: Update md5 to better report errors with hashlib
In the case where hashlib is not available, the try would fail and fall through resulting in a backtrace on the usage of the 'sig'. The backtrace itself was confusing and made it difficult to determine what went wrong. Update the import to be in it's own try block with an appropriate message to indicate what went wrong. Note, the current version of ply all of this code has been restructured so this is not applicable upstream. Additionally, some versions of hashlib don't appear to implement the second FIPS related argument. Detect this and support both versions. Signed-off-by: Mark Hatle <mark.hatle@amd.com> Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> (cherry picked from commit 484ab42f440070c0369b81f5c69da860fa47a798) Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--lib/bb/utils.py7
-rw-r--r--lib/ply/yacc.py7
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 66a8a08c2..bca4830f2 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -545,7 +545,12 @@ def md5_file(filename):
Return the hex string representation of the MD5 checksum of filename.
"""
import hashlib
- return _hasher(hashlib.new('MD5', usedforsecurity=False), filename)
+ try:
+ sig = hashlib.new('MD5', usedforsecurity=False)
+ except TypeError:
+ # Some configurations don't appear to support two arguments
+ sig = hashlib.new('MD5')
+ return _hasher(sig, filename)
def sha256_file(filename):
"""
diff --git a/lib/ply/yacc.py b/lib/ply/yacc.py
index 767c4e467..381b50cf0 100644
--- a/lib/ply/yacc.py
+++ b/lib/ply/yacc.py
@@ -2798,7 +2798,14 @@ class ParserReflect(object):
def signature(self):
try:
import hashlib
+ except ImportError:
+ raise RuntimeError("Unable to import hashlib")
+ try:
sig = hashlib.new('MD5', usedforsecurity=False)
+ except TypeError:
+ # Some configurations don't appear to support two arguments
+ sig = hashlib.new('MD5')
+ try:
if self.start:
sig.update(self.start.encode('latin-1'))
if self.prec: