[oe-commits] [bitbake] 02/02: codeparser: Use hashlib for hashing, not hash()

git at git.openembedded.org git at git.openembedded.org
Fri Jun 3 12:49:43 UTC 2016


rpurdie pushed a commit to branch master
in repository bitbake.

commit 12d43cf45ba48e3587392f15315d92a1a53482ef
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Fri Jun 3 13:38:33 2016 +0100

    codeparser: Use hashlib for hashing, not hash()
    
    "hash() is randomised by default each time you start a new instance of
    recent
    versions (Python3.3+) to prevent dictionary insertion DOS attacks"
    
    which means we need to use hashlib.md5 to get consistent values for
    the codeparser cache under python 3. Prior to this, the codeparser
    cache was effectively useless under python3 as shown by performance
    regressions.
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 lib/bb/codeparser.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/bb/codeparser.py b/lib/bb/codeparser.py
index 6ed2ade..25938d6 100644
--- a/lib/bb/codeparser.py
+++ b/lib/bb/codeparser.py
@@ -6,12 +6,16 @@ import pickle
 import bb.pysh as pysh
 import os.path
 import bb.utils, bb.data
+import hashlib
 from itertools import chain
 from bb.pysh import pyshyacc, pyshlex, sherrors
 from bb.cache import MultiProcessCache
 
 logger = logging.getLogger('BitBake.CodeParser')
 
+def bbhash(s):
+    return hashlib.md5(s.encode("utf-8")).hexdigest()
+
 def check_indent(codestr):
     """If the code is indented, add a top level piece of code to 'remove' the indentation"""
 
@@ -270,7 +274,7 @@ class PythonParser():
         if not node or not node.strip():
             return
 
-        h = hash(str(node))
+        h = bbhash(str(node))
 
         if h in codeparsercache.pythoncache:
             self.references = set(codeparsercache.pythoncache[h].refs)
@@ -315,7 +319,7 @@ class ShellParser():
         commands it executes.
         """
 
-        h = hash(str(value))
+        h = bbhash(str(value))
 
         if h in codeparsercache.shellcache:
             self.execs = set(codeparsercache.shellcache[h].execs)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list