summaryrefslogtreecommitdiff
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-02-20 21:44:56 -0500
committerBenjamin Peterson <benjamin@python.org>2012-02-20 21:44:56 -0500
commitaee9dfba4a9230f2832dd69d67e92f8e0490a163 (patch)
tree27a9896969ac7ff79dc75017cff121a077c3eb6e /Objects/unicodeobject.c
parent34b345b8885e5db8ab6627c081ca86a8b78b6989 (diff)
parentb19fb2462eac776746f6cb40cc84b0587c83b9bc (diff)
downloadcpython-git-aee9dfba4a9230f2832dd69d67e92f8e0490a163.tar.gz
merge 2.6 with hash randomization fix
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 84252ecae6..a65defff60 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6541,11 +6541,21 @@ unicode_hash(PyUnicodeObject *self)
if (self->hash != -1)
return self->hash;
len = PyUnicode_GET_SIZE(self);
+ /*
+ We make the hash of the empty string be 0, rather than using
+ (prefix ^ suffix), since this slightly obfuscates the hash secret
+ */
+ if (len == 0) {
+ self->hash = 0;
+ return 0;
+ }
p = PyUnicode_AS_UNICODE(self);
- x = *p << 7;
+ x = _Py_HashSecret.prefix;
+ x ^= *p << 7;
while (--len >= 0)
x = (1000003*x) ^ *p++;
x ^= PyUnicode_GET_SIZE(self);
+ x ^= _Py_HashSecret.suffix;
if (x == -1)
x = -2;
self->hash = x;