gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module#145476
gh-145376: Fix refleak and null pointer deref in unusual error path of datetime module#145476eendebakpt wants to merge 3 commits intopython:mainfrom
Conversation
StanFromIreland
left a comment
There was a problem hiding this comment.
I think this should get a news entry.
Added the news entry, although I think we can skip it since the changes are only in very rare paths. |
That's my assesment too. It's technically a user-visible change, but that user needs to squint really hard. |
| PyErr_Format(PyExc_TypeError, "utcoffset() returned %.200s," | ||
| " expected timedelta or None", Py_TYPE(offset)->tp_name); |
There was a problem hiding this comment.
While we are here, you can use %T which is safer and provides more accurate representation:
| PyErr_Format(PyExc_TypeError, "utcoffset() returned %.200s," | |
| " expected timedelta or None", Py_TYPE(offset)->tp_name); | |
| PyErr_Format(PyExc_TypeError, "utcoffset() returned %T," | |
| " expected timedelta or None", offset); |
| @@ -0,0 +1 @@ | |||
| Fix refleak and null pointer deref in unusual error path of :mod:`datetime`. | |||
There was a problem hiding this comment.
Please remove it, users should not be impacted by this change. The error case is very unlikely.
There was a problem hiding this comment.
I suggested adding it since this PR covers several cases increasing the likelyhood of one of them being hit. If you think it is better to remove it, I don't mind.
There was a problem hiding this comment.
Usually, we don't document such fix for an unlikely corner case.
PyLong_FromLong() can only fail if the system has no more free memory.
datetime.datetime.astimezone() reads freed memory, but it only occurs if utcoffset() returns the wrong type. It seems like nobody reported the issue (with a reproducer), so it sounds unlikely to crash in practice (reading freed memory just works in the common case).
Uh oh!
There was an error while loading. Please reload this page.