diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-03 13:38:33 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-03 13:48:33 +0100 |
commit | 438ac3262851b3915ac8c37db7800b8a9008068c (patch) | |
tree | 737a62e8d89dae388372d0701507d033ef94b27e /bitbake/lib | |
parent | 5f2facfc1dd80d28b2734bc7592e4b7c73cdb828 (diff) | |
download | poky-438ac3262851b3915ac8c37db7800b8a9008068c.tar.gz |
bitbake: 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.
(Bitbake rev: 12d43cf45ba48e3587392f15315d92a1a53482ef)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/codeparser.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 6ed2adeed9..25938d6586 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py | |||
@@ -6,12 +6,16 @@ import pickle | |||
6 | import bb.pysh as pysh | 6 | import bb.pysh as pysh |
7 | import os.path | 7 | import os.path |
8 | import bb.utils, bb.data | 8 | import bb.utils, bb.data |
9 | import hashlib | ||
9 | from itertools import chain | 10 | from itertools import chain |
10 | from bb.pysh import pyshyacc, pyshlex, sherrors | 11 | from bb.pysh import pyshyacc, pyshlex, sherrors |
11 | from bb.cache import MultiProcessCache | 12 | from bb.cache import MultiProcessCache |
12 | 13 | ||
13 | logger = logging.getLogger('BitBake.CodeParser') | 14 | logger = logging.getLogger('BitBake.CodeParser') |
14 | 15 | ||
16 | def bbhash(s): | ||
17 | return hashlib.md5(s.encode("utf-8")).hexdigest() | ||
18 | |||
15 | def check_indent(codestr): | 19 | def check_indent(codestr): |
16 | """If the code is indented, add a top level piece of code to 'remove' the indentation""" | 20 | """If the code is indented, add a top level piece of code to 'remove' the indentation""" |
17 | 21 | ||
@@ -270,7 +274,7 @@ class PythonParser(): | |||
270 | if not node or not node.strip(): | 274 | if not node or not node.strip(): |
271 | return | 275 | return |
272 | 276 | ||
273 | h = hash(str(node)) | 277 | h = bbhash(str(node)) |
274 | 278 | ||
275 | if h in codeparsercache.pythoncache: | 279 | if h in codeparsercache.pythoncache: |
276 | self.references = set(codeparsercache.pythoncache[h].refs) | 280 | self.references = set(codeparsercache.pythoncache[h].refs) |
@@ -315,7 +319,7 @@ class ShellParser(): | |||
315 | commands it executes. | 319 | commands it executes. |
316 | """ | 320 | """ |
317 | 321 | ||
318 | h = hash(str(value)) | 322 | h = bbhash(str(value)) |
319 | 323 | ||
320 | if h in codeparsercache.shellcache: | 324 | if h in codeparsercache.shellcache: |
321 | self.execs = set(codeparsercache.shellcache[h].execs) | 325 | self.execs = set(codeparsercache.shellcache[h].execs) |