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' U_set() doesn't check return value of PyUnicode_AsWideChar()
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, christian.heimes, mrabarnett, python-dev
Priority: low Keywords:

Created on 2013-07-25 16:52 by christian.heimes, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg193703 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-25 16:52
http://hg.python.org/cpython/file/be5f1f0bea09/Modules/_ctypes/cfield.c#l1235

CID 486657 (#1 of 1): Unchecked return value (CHECKED_RETURN)
5. check_return: Calling function "PyUnicode_AsWideChar(PyObject *, wchar_t *, Py_ssize_t)" without checking return value (as is done elsewhere 7 out of 8 times).
1263    PyUnicode_AsWideChar(value, (wchar_t *)ptr, size);
msg193715 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2013-07-25 19:28
Re msg193703: A little before that, 'value' is INCREF'ed, and then:

    wstr = PyUnicode_AsUnicodeAndSize(value, &size);
    if (wstr == NULL)
        return NULL;

Shouldn't 'value' be DECREF'ed before returning?
msg193720 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-25 21:36
New changeset 78e8980ec9f7 by Brett Cannon in branch '3.3':
Issue #18556: Check the return value for PyUnicode_AsWideChar() in
http://hg.python.org/cpython/rev/78e8980ec9f7

New changeset 2f4c4db9aee5 by Brett Cannon in branch 'default':
merge for issue #18556
http://hg.python.org/cpython/rev/2f4c4db9aee5
msg193722 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-07-25 21:37
Thanks for the check, Matthew, but if you look at the other *_set() methods they do not necessarily DECREF their 'value' argument. Plus if PyUnicode_AsWideChar() fails it means memory is full or a fatal error has triggered, so there are bigger worries. =)
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62756
2013-07-25 21:37:45brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg193722

resolution: fixed
stage: needs patch -> resolved
2013-07-25 21:36:39python-devsetnosy: + python-dev
messages: + msg193720
2013-07-25 19:28:43mrabarnettsetnosy: + mrabarnett
messages: + msg193715
2013-07-25 16:52:29christian.heimescreate