[tor-commits] [stem/master] Dictionaries could cause equality checks to fail

atagar at torproject.org atagar at torproject.org
Wed Aug 30 16:40:51 UTC 2017


commit d4ae5b775941b54b9303a88a33e21831f0e6fffa
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Aug 29 10:57:15 2017 -0700

    Dictionaries could cause equality checks to fail
    
    Dictionaries, of course, aren't assured to have the same key ordering unless
    we're using an OrderedDict. Previously we constructed dictionaries in the same
    order because configs are ordered, but this is no longer the case with sqlite.
    
    Fixing our hashing function to not care about order.
---
 stem/util/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/stem/util/__init__.py b/stem/util/__init__.py
index 5ee5d5fb..242a3110 100644
--- a/stem/util/__init__.py
+++ b/stem/util/__init__.py
@@ -67,8 +67,8 @@ def _hash_attr(obj, *attributes, **kwargs):
 
     if attr_value is not None:
       if isinstance(attr_value, dict):
-        for k, v in attr_value.items():
-          my_hash = (my_hash + hash(k)) * 1024 + hash(v)
+        for k in sorted(attr_value.keys()):
+          my_hash = (my_hash + hash(k)) * 1024 + hash(attr_value[k])
       else:
         my_hash += hash(attr_value)
 





More information about the tor-commits mailing list