Author eryksun
Recipients Alex Wang, docs@python, eryksun
Date 2016-11-15.18:53:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479235992.16.0.561556781345.issue28698@psf.upfronthosting.co.za>
In-reply-to
Content
The repr can't automatically dereference the string at the address because it may be an invalid pointer. ctypes was developed on Windows, for which, in Python 2, it (ab)uses the obsolete IsBadStringPtr[A|W] function [1]. This function should never be used in a multithreaded process. 

On POSIX systems, the repr of c_char_p was special-cased to avoid dereferencing the pointer, but c_wchar_p was overlooked, and you can still easily crash Python 2 like this:

    Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import ctypes
    >>> ctypes.c_wchar_p(1)
    Segmentation fault (core dumped

A while back the bogus use of WinAPI IsBadStringPtr was removed from the Python 3 branch, but apparently the docs weren't updated to reflect this change. I'm changing this to a documentation issue.

[1]: https://msdn.microsoft.com/en-us/library/aa366714
History
Date User Action Args
2016-11-15 18:53:12eryksunsetrecipients: + eryksun, docs@python, Alex Wang
2016-11-15 18:53:12eryksunsetmessageid: <1479235992.16.0.561556781345.issue28698@psf.upfronthosting.co.za>
2016-11-15 18:53:12eryksunlinkissue28698 messages
2016-11-15 18:53:11eryksuncreate