You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
segfaults calling warnings.warn() with non-string message #47889
If you search for _PyUnicode_AsString() in Python/_warnings.c you will
find several places that assume that the proper measures have been taken
to make sure the object is a string. All of those places need to be
fixed so that if a string is not passed in then one is grabbed.
And the reason this turned out as a segfault is for a missing error
return value just before the strcmp() call.
devdanzin commented on Aug 22, 2008
devdanzinmannequin
Mannequin
More actions
Brett,
I don't think I know C (and CPython) enough to fix this. I was able to
get rid of this specific segfault with this:
But I have no idea whether I should also incref/decref the PyObject_Str.
That's along the lines of what needs to be done (and what I was
planning on doing), although you need to do more error checking on the
return values. Plus the patch I am cooking up adds more checks in the
code for the return value of _PyUnicode_AsString().
The patch doesn't actually bother with a translation as the code causing
issue is only there to prevent infinite recursion. So if the object
being used is not a string, then there is no need to worry as it is not
part of the infinite recursion problem.
Activity
dalcinl commentedon Aug 21, 2008
devdanzin commentedon Aug 22, 2008
Two small clues.
First, a backtrace:
That is, _warnings.warn(spam) works OK and avoids the
warnings.warn(spam) crash for values already called by the former.
brettcannon commentedon Aug 22, 2008
If you search for _PyUnicode_AsString() in Python/_warnings.c you will
find several places that assume that the proper measures have been taken
to make sure the object is a string. All of those places need to be
fixed so that if a string is not passed in then one is grabbed.
And the reason this turned out as a segfault is for a missing error
return value just before the strcmp() call.
devdanzin commentedon Aug 22, 2008
Brett,
I don't think I know C (and CPython) enough to fix this. I was able to
get rid of this specific segfault with this:
+ const char *text_char =
_PyUnicode_AsString(PyObject_Str(text));
But I have no idea whether I should also incref/decref the PyObject_Str.
brettcannon commentedon Aug 22, 2008
On Fri, Aug 22, 2008 at 8:03 AM, Daniel Diniz <report@bugs.python.org> wrote:
That's along the lines of what needs to be done (and what I was
planning on doing), although you need to do more error checking on the
return values. Plus the patch I am cooking up adds more checks in the
code for the return value of _PyUnicode_AsString().
brettcannon commentedon Aug 22, 2008
The patch doesn't actually bother with a translation as the code causing
issue is only there to prevent infinite recursion. So if the object
being used is not a string, then there is no need to worry as it is not
part of the infinite recursion problem.
I also added a bunch of missing error checks.
benjaminp commentedon Aug 22, 2008
Brett, is this patch ready for review?
brettcannon commentedon Aug 22, 2008
That's why the keyword is set. =)
benjaminp commentedon Aug 22, 2008
On Fri, Aug 22, 2008 at 2:59 PM, Brett Cannon <report@bugs.python.org> wrote:
Ah. I missed that. :) The patch looks fine.
--
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."
brettcannon commentedon Sep 2, 2008
Checked in r66140.