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: PyDict_SetItemString() fails when the second argument is null
Type: crash Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: eulerto, georg.brandl, loewis, rhettinger
Priority: normal Keywords:

Created on 2009-03-31 16:47 by eulerto, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg84833 - (view) Author: Euler Taveira de Oliveira (eulerto) Date: 2009-03-31 16:47
PyDict_SetItemString() fails when the second argument (key) is null
pointer. It occurs because PyString_FromString(key) call doesn't check
for null pointer and if we're in a disabled assert environment the
assert() is not caught and strlen() fails.

I don't know what is the best fix but we have two possibilities:

(i) check the second argument in PyDict_SetItemString() before calling
PyString_FromString() and returns null if that argument is null;
(ii) replace the assert() in PyString_FromString() to 'if (str == NULL)
return NULL;'.

This bug was reported as a PostgreSQL bug at [1].

[1] http://archives.postgresql.org/pgsql-hackers/2009-03/msg01344.php
msg84851 - (view) Author: Euler Taveira de Oliveira (eulerto) Date: 2009-03-31 18:20
It seems PyDict_DelItemString() and PyDict_SetItem() suffer from the
same disease. :( Both use assert() to detect a null pointer but fail to
prevent it. As I stated in the previous comment, maybe the right fix is
to replace assert() with the 'if (foo == NULL) return whatever'.
msg84978 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-01 04:30
I am not sure why you consider this a bug. You should certainly not pass
NULL pointers around where the docs do not explicitly allow this.
msg84983 - (view) Author: Euler Taveira de Oliveira (eulerto) Date: 2009-04-01 05:33
I know that it is a good programming practice checking null pointers but
sometimes programmers are lazy. ;)  I still think that high level
functions should check for null pointers.
msg85114 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-01 23:12
Raymond, do you have an opinion about this?
msg85142 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-04-02 02:46
I recommend rejecting this one.  The assert is sufficient for
third-party modules to run their tests and detect bad calls.  The code
path is too critical to add another check.
msg85145 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-02 02:52
Closing.
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49877
2009-04-02 02:52:51georg.brandlsetstatus: open -> closed

messages: + msg85145
2009-04-02 02:46:14rhettingersetassignee: loewis -> georg.brandl
messages: + msg85142
2009-04-02 02:44:40rhettingersetmessages: - msg85138
2009-04-02 02:44:32rhettingersetmessages: - msg85134
2009-04-02 02:29:36loewissetmessages: + msg85138
title: PyDict_SetItemString() fails when the second argument is null -> PyDict_SetItemString() fails when the second argument is null
2009-04-02 01:46:45rhettingersetstatus: pending -> open

nosy: + loewis
messages: + msg85134

assignee: rhettinger -> loewis
2009-04-01 23:12:39georg.brandlsetassignee: rhettinger

messages: + msg85114
nosy: + rhettinger
2009-04-01 05:33:13eulertosetmessages: + msg84983
2009-04-01 04:30:56georg.brandlsetstatus: open -> pending

nosy: + georg.brandl
messages: + msg84978

resolution: wont fix
2009-03-31 18:20:38eulertosetmessages: + msg84851
2009-03-31 16:47:12eulertocreate