Issue 17708: sys.flags.hash_randomization doesn't return correct value (original ) (raw )Created on 2013-04-13 05:46 by msmhrt , last changed 2022-04-11 14:57 by admin . This issue is now closed .
Messages (6)
msg186693 - (view)
Author: Masami HIRATA (msmhrt)
Date: 2013-04-13 05:46
OS: Windows 7 Starter Edition SP1 (32-bit) Python: 3.3.1 (python-3.3.1.msi) It seems that sys.flags.hash_randomization doesn't return correct value Output: C:\>set PYTHONHASHSEED=random C:\>C:\Python33\python.exe Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:25:12) [MSC v.1600 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.flags.hash_randomization 1 >>> ^Z C:\>set PYTHONHASHSEED=1 C:\>C:\Python33\python.exe Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:25:12) [MSC v.1600 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.flags.hash_randomization 1 >>> ^Z C:\>set PYTHONHASHSEED=12345 C:\>C:\Python33\python.exe ... >>> import sys >>> sys.flags.hash_randomization 12345 >>> ^Z Output I Expected: C:\>set PYTHONHASHSEED=random C:\>C:\Python33\python.exe ... >>> import sys >>> sys.flags.hash_randomization True >>> ^Z C:\>set PYTHONHASHSEED=1 C:\>C:\Python33\python.exe ... >>> import sys >>> sys.flags.hash_randomization False >>> ^Z C:\>set PYTHONHASHSEED=12345 C:\>C:\Python33\python.exe ... >>> import sys >>> sys.flags.hash_randomization False >>> ^Z
msg186777 - (view)
Author: Stephen Tu (Stephen.Tu) *
Date: 2013-04-13 18:16
Py_HashRandomizationFlag was not getting properly set anywhere. This patch fixes this. Also a test case Behavior is now: $ cat ~/hr.py import sys print(sys.flags.hash_randomization) $ PYTHONHASHSEED=random ./python.exe ~/hr.py 1 $ PYTHONHASHSEED=0 ./python.exe ~/hr.py 0 $ PYTHONHASHSEED=1 ./python.exe ~/hr.py 0
msg186870 - (view)
Author: Masami HIRATA (msmhrt)
Date: 2013-04-14 00:37
It seems there is a misunderstanding on my part. Python v3.3.1 documentation says, "sys.flags The struct sequence flags exposes the status of command line flags. The attributes are read only." I think that sys.flags.hash_randomization should be always 1 on Python v3.3.1 because the documentation says, "-R Kept for compatibility. On Python 3.3 and greater, hash randomization is turned on by default."
msg186871 - (view)
Author: Stephen Tu (Stephen.Tu) *
Date: 2013-04-14 00:56
But it would seem that setting PYTHONHASHSEED != "random" does disable hash randomization. also, not sure what the semantics of the following is: $ PYTHONHASHSEED=1 python -R ... right now, python3 basically ignores -R.
msg186872 - (view)
Author: Masami HIRATA (msmhrt)
Date: 2013-04-14 01:14
We should add 'randomization' and 'seed' attribute to sys.hash_info, I think.
msg407152 - (view)
Author: Irit Katriel (iritkatriel) *
Date: 2021-11-27 15:33
This is working now (note that since 3.10 hash randomisation is enabled by default): cpython % export PYTHONHASHSEED=random cpython % ./python.exe -c "import sys; print(sys.flags.hash_randomization)" 1 cpython % export PYTHONHASHSEED=0 cpython % ./python.exe -c "import sys; print(sys.flags.hash_randomization)" 0 cpython % export PYTHONHASHSEED=1 cpython % ./python.exe -c "import sys; print(sys.flags.hash_randomization)" 1
History
Date
User
Action
Args
2022-04-11 14:57:44
admin
set
github: 61908
2021-11-27 15:33:08
iritkatriel
set
status: open -> closednosy: + iritkatriel messages: + resolution: out of datestage: resolved
2013-04-15 13:41:49
benjamin.peterson
set
nosy: + dmalcolm
2013-04-15 12:15:12
christian.heimes
set
nosy: + christian.heimes
2013-04-14 01:14:22
msmhrt
set
messages: +
2013-04-14 00:56:57
Stephen.Tu
set
messages: +
2013-04-14 00:37:10
msmhrt
set
messages: +
2013-04-13 18:16:44
Stephen.Tu
set
files: + hashrandomization.patch nosy: + Stephen.Tu messages: + keywords: + patch
2013-04-13 05:46:48
msmhrt
create