diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-02-21 02:44:56 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-02-21 02:44:56 (GMT) |
commit | aee9dfba4a9230f2832dd69d67e92f8e0490a163 (patch) | |
tree | 27a9896969ac7ff79dc75017cff121a077c3eb6e /Objects/stringobject.c | |
parent | 34b345b8885e5db8ab6627c081ca86a8b78b6989 (diff) | |
parent | b19fb2462eac776746f6cb40cc84b0587c83b9bc (diff) | |
download | cpython-aee9dfba4a9230f2832dd69d67e92f8e0490a163.zip cpython-aee9dfba4a9230f2832dd69d67e92f8e0490a163.tar.gz cpython-aee9dfba4a9230f2832dd69d67e92f8e0490a163.tar.bz2 |
merge 2.6 with hash randomization fix
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index d6c4f77..49d1864 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1265,11 +1265,21 @@ string_hash(PyStringObject *a) if (a->ob_shash != -1) return a->ob_shash; len = Py_SIZE(a); + /* + 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) { + a->ob_shash = 0; + return 0; + } p = (unsigned char *) a->ob_sval; - x = *p << 7; + x = _Py_HashSecret.prefix; + x ^= *p << 7; while (--len >= 0) x = (1000003*x) ^ *p++; x ^= Py_SIZE(a); + x ^= _Py_HashSecret.suffix; if (x == -1) x = -2; a->ob_shash = x; |