Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9a3591

Browse files
committed
merge 3.2
2 parents 8b24506 + e249dca commit d9a3591

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

Include/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ typedef struct {
560560
} _Py_HashSecret_t;
561561
PyAPI_DATA(_Py_HashSecret_t) _Py_HashSecret;
562562

563+
#ifdef Py_DEBUG
564+
PyAPI_DATA(int) _Py_HashSecret_Initialized;
565+
#endif
566+
563567
/* Helper for passing objects to printf and the like */
564568
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
565569

Objects/object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ _Py_HashBytes(unsigned char *p, Py_ssize_t len)
763763
We make the hash of the empty string be 0, rather than using
764764
(prefix ^ suffix), since this slightly obfuscates the hash secret
765765
*/
766+
assert(_Py_HashSecret_Initialized);
766767
if (len == 0) {
767768
return 0;
768769
}

Objects/unicodeobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11214,6 +11214,7 @@ unicode_hash(PyObject *self)
1121411214
Py_ssize_t len;
1121511215
Py_uhash_t x;
1121611216

11217+
assert(_Py_HashSecret_Initialized);
1121711218
if (_PyUnicode_HASH(self) != -1)
1121811219
return _PyUnicode_HASH(self);
1121911220
if (PyUnicode_READY(self) == -1)

Python/random.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <fcntl.h>
66
#endif
77

8-
static int random_initialized = 0;
8+
#ifdef Py_DEBUG
9+
int _Py_HashSecret_Initialized = 0;
10+
#else
11+
static int _Py_HashSecret_Initialized = 0;
12+
#endif
913

1014
#ifdef MS_WINDOWS
1115
typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv,\
@@ -246,11 +250,11 @@ _PyRandom_Init(void)
246250
{
247251
char *env;
248252
void *secret = &_Py_HashSecret;
249-
Py_ssize_t secret_size = sizeof(_Py_HashSecret);
253+
Py_ssize_t secret_size = sizeof(_Py_HashSecret_t);
250254

251-
if (random_initialized)
255+
if (_Py_HashSecret_Initialized)
252256
return;
253-
random_initialized = 1;
257+
_Py_HashSecret_Initialized = 1;
254258

255259
/*
256260
By default, hash randomization is disabled, and only

0 commit comments

Comments
 (0)