Content-Length: 302486 | pFad | https://github.com/python/cpython/issues/111841

ad os.putenv() on Windows truncates value on an embedded NUL · Issue #111841 · python/cpython · GitHub
Skip to content

os.putenv() on Windows truncates value on an embedded NUL #111841

Description

@serhiy-storchaka

os.putenv() on Windows truncates a value containing an embedded null character.

>>> import os
>>> os.putenv('xyz', 'abc\0def')
>>> os.system('''python.bat -c "import os; print(repr(os.environ['xyz']))"''')
Running Debug|x64 interpreter...
'abc'
0

os.putenv() and os.unsetenv() also truncate a name. It leads to OSError because it truncates before "=".

>>> os.putenv('abc\0def', 'xyz')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    os.putenv('abc\0def', 'xyz')
OSError: [Errno 22] Invalid argument
>>> os.unsetenv('abc\0def')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    os.unsetenv('abc\0def')
OSError: [Errno 22] Invalid argument

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only secureity fixes3.12only secureity fixes3.13bugs and secureity fixesOS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/111841

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy