Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyDict_SetItemString() fails when the second argument is null #49877

Closed
eulerto mannequin opened this issue Mar 31, 2009 · 7 comments
Closed

PyDict_SetItemString() fails when the second argument is null #49877

eulerto mannequin opened this issue Mar 31, 2009 · 7 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@eulerto
Copy link
Mannequin

eulerto mannequin commented Mar 31, 2009

BPO 5627
Nosy @loewis, @birkenfeld, @rhettinger

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2009-04-02.02:52:51.436>
created_at = <Date 2009-03-31.16:47:12.008>
labels = ['interpreter-core', 'type-crash']
title = 'PyDict_SetItemString() fails when the second argument is\tnull'
updated_at = <Date 2009-04-02.02:52:51.415>
user = 'https://bugs.python.org/eulerto'

bugs.python.org fields:

activity = <Date 2009-04-02.02:52:51.415>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2009-04-02.02:52:51.436>
closer = 'georg.brandl'
components = ['Interpreter Core']
creation = <Date 2009-03-31.16:47:12.008>
creator = 'eulerto'
dependencies = []
files = []
hgrepos = []
issue_num = 5627
keywords = []
message_count = 7.0
messages = ['84833', '84851', '84978', '84983', '85114', '85142', '85145']
nosy_count = 4.0
nosy_names = ['loewis', 'georg.brandl', 'rhettinger', 'eulerto']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'crash'
url = 'https://bugs.python.org/issue5627'
versions = []

@eulerto
Copy link
Mannequin Author

eulerto mannequin commented Mar 31, 2009

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

@eulerto eulerto mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Mar 31, 2009
@eulerto
Copy link
Mannequin Author

eulerto mannequin commented Mar 31, 2009

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'.

@birkenfeld
Copy link
Member

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.

@eulerto
Copy link
Mannequin Author

eulerto mannequin commented Apr 1, 2009

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.

@birkenfeld
Copy link
Member

Raymond, do you have an opinion about this?

@rhettinger rhettinger assigned loewis and unassigned rhettinger Apr 2, 2009
@loewis loewis mannequin changed the title PyDict_SetItemString() fails when the second argument is null PyDict_SetItemString() fails when the second argument is null Apr 2, 2009
@rhettinger
Copy link
Contributor

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.

@rhettinger rhettinger assigned birkenfeld and unassigned loewis Apr 2, 2009
@birkenfeld
Copy link
Member

Closing.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

2 participants