[issue25778] winreg.EnumValue does not truncate strings correctly

Eryk Sun report at bugs.python.org
Thu Dec 3 12:52:00 EST 2015


Eryk Sun added the comment:

> I don't like the idea of having a mismatch between what we set and
> what we get, even if what we're setting technically shouldn't be 
> allowed.

Currently if you set a string with null, you won't see it using either regedit.exe or reg.exe:

    >>> import os, winreg
    >>> data = "a string\x00 with a null"
    >>> HKCU = winreg.HKEY_CURRENT_USER
    >>> winreg.SetValueEx(HKCU, "test", 0, winreg.REG_SZ, data)
    >>> winreg.QueryValueEx(HKCU, "test")
    ('a string\x00 with a null', 1)

    >>> os.system('reg query HKCU /v test')

    HKEY_CURRENT_USER
        test    REG_SZ    a string

    0

The registry saves the whole buffer, agnostic to the type, but clearly Microsoft has documented and treats REG_SZ as a null-terminated string. We should follow suit.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25778>
_______________________________________


More information about the Python-bugs-list mailing list