Skip to contentSkip to conversation

utils/ply: Update md5 to better report errors with hashlib

PATCH Mark Hatle 1 participant 1 message Oct 25, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Mark Hatle

author
#1 lore raw

Ping on this one.

Quoted 71 lines · Mark Hatle

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.

---
This was found on an internal Ubuntu 18.04 container. Unfortunately I don't have access to the container itself but this resolves the issue.

  bitbake/lib/bb/utils.py | 7 ++++++-
  bitbake/lib/ply/yacc.py | 7 +++++++
  2 files changed, 13 insertions(+), 1 deletion(-)
lib/bb/utils.py +6 -1
index e6e21e20fe..64a004d0d8 100644
@@ -547,7 +547,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):
      """
lib/ply/yacc.py +7 -1
index 767c4e4674..381b50cf0b 100644
@@ -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:
 
 
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#14027): https://lists.openembedded.org/g/bitbake-devel/message/14027
Mute This Topic: https://lists.openembedded.org/mt/94168114/3616948
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-