homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctypes segfaults when passing a unicode string to a function without argtypes
Type: crash Stage:
Components: ctypes Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: amaury.forgeotdarc, theller
Priority: normal Keywords:

Created on 2009年02月10日 12:48 by amaury.forgeotdarc, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (2)
msg81544 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009年02月10日 12:48
The following code segfaults on platforms where HAVE_USABLE_WCHAR_T is
not defined (for example: narrow unicode build and sizeof(wchar_t)==4)
>>> from ctypes import *
>>> import ctypes.util
>>> CDLL(ctypes.util.find_library('c')).wcslen(u'text')
(it works if the argtypes member is defined)
The reason is a non initialized structure, and the correction is trivial:
--- Modules/_ctypes/callproc.c~ 2007年06月15日 19:10:41.000000000 +0200
+++ Modules/_ctypes/callproc.c 2009年02月10日 13:28:10.000000000 +0100
@@ -538,6 +538,7 @@
 int size = PyUnicode_GET_SIZE(obj);
 size += 1; /* terminating NUL */
 size *= sizeof(wchar_t);
+ pa->ffi_type = &ffi_type_pointer;
 pa->value.p = PyMem_Malloc(size);
 if (!pa->value.p) {
 PyErr_NoMemory();
msg81582 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2009年02月10日 19:07
Fixed in trunk (rev 69505) and release26-maint (rev 69506).
The bug was already fixed in a different way in py3k and release30-maint
although in a different way, I merged this exact fix anyway (rev 69507
and rev 69508).
Thanks.
History
Date User Action Args
2022年04月11日 14:56:45adminsetgithub: 49453
2009年02月10日 19:07:27thellersetstatus: open -> closed
resolution: fixed
messages: + msg81582
versions: + Python 2.7
2009年02月10日 12:48:03amaury.forgeotdarccreate

AltStyle によって変換されたページ (->オリジナル) /