aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Eike Beer <eike@sf-mail.de>2018-05-13 04:40:03 -0700
committerMichał Górny <mgorny@gentoo.org>2019-12-29 11:31:44 +0100
commitbb9f847eed94085a30fbf99729d227c1a604ae34 (patch)
tree1127a9a1f9a0020087ca5e19637e8587d47bbfa8
parentDisable nis (diff)
downloadcpython-gentoo-3.5.9.tar.gz
cpython-gentoo-3.5.9.tar.bz2
cpython-gentoo-3.5.9.zip
bpo-28055: Fix unaligned accesses in siphash24(). (GH-6123)gentoo-3.5.9
The hash implementation casts the input pointer to uint64_t* and directly reads from this, which may cause unaligned accesses. Use memcpy() instead so this code will not crash with SIGBUS on sparc.
-rw-r--r--Python/pyhash.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Python/pyhash.c b/Python/pyhash.c
index 97cb54759b6..e105c15b32c 100644
--- a/Python/pyhash.c
+++ b/Python/pyhash.c
@@ -372,7 +372,7 @@ siphash24(const void *src, Py_ssize_t src_sz) {
PY_UINT64_T k0 = _le64toh(_Py_HashSecret.siphash.k0);
PY_UINT64_T k1 = _le64toh(_Py_HashSecret.siphash.k1);
PY_UINT64_T b = (PY_UINT64_T)src_sz << 56;
- const PY_UINT64_T *in = (PY_UINT64_T*)src;
+ const PY_UINT8_T *in = (PY_UINT8_T*)src;
PY_UINT64_T v0 = k0 ^ 0x736f6d6570736575ULL;
PY_UINT64_T v1 = k1 ^ 0x646f72616e646f6dULL;
@@ -381,12 +381,14 @@ siphash24(const void *src, Py_ssize_t src_sz) {
PY_UINT64_T t;
PY_UINT8_T *pt;
- PY_UINT8_T *m;
+ const PY_UINT8_T *m;
while (src_sz >= 8) {
- PY_UINT64_T mi = _le64toh(*in);
- in += 1;
- src_sz -= 8;
+ PY_UINT64_T mi;
+ memcpy(&mi, in, sizeof(mi));
+ mi = _le64toh(mi);
+ in += sizeof(mi);
+ src_sz -= sizeof(mi);
v3 ^= mi;
DOUBLE_ROUND(v0,v1,v2,v3);
v0 ^= mi;
@@ -394,7 +396,7 @@ siphash24(const void *src, Py_ssize_t src_sz) {
t = 0;
pt = (PY_UINT8_T *)&t;
- m = (PY_UINT8_T *)in;
+ m = in;
switch (src_sz) {
case 7: pt[6] = m[6];
case 6: pt[5] = m[5];