-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-111178: fix UBSan failures in Modules/_datetimemodule.c
#129774
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
Conversation
Ah I'm sorry I put this one as ready for review but I learned that |
…n into fix/ubsan/datetime-111178
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nitpicks most probably related to mechanical changes.
At some places, the casts would not be needed and the PR could be kept smaller.
Most probably you'd still want the renamings like
time_utcoffset(PyObject *op, PyObject *Py_UNUSED(dummy))
for consistency with the rest of the PR, even though there and at some other places no change would be needed at all.
Tried to locate them, hopefully no false positives - need a break now :)
So just happily ignore where not appropriate.
@@ -4665,17 +4697,20 @@ time_dealloc(PyDateTime_Time *self) | |||
|
|||
/* These are all METH_NOARGS, so don't need to check the arglist. */ | |||
static PyObject * | |||
time_utcoffset(PyObject *self, PyObject *unused) { | |||
time_utcoffset(PyObject *op, PyObject *Py_UNUSED(dummy)) { | |||
PyDateTime_Time *self = PyTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the PR, time_utcoffset
already got a PyObject
as first parameter and GET_TIME_TZINFO
happily accepts it.
Maybe omit the PyTime_CAST
to keep the diff smaller?
return call_utcoffset(GET_TIME_TZINFO(self), Py_None); | ||
} | ||
|
||
static PyObject * | ||
time_dst(PyObject *self, PyObject *unused) { | ||
time_dst(PyObject *op, PyObject *Py_UNUSED(dummy)) { | ||
PyDateTime_Time *self = PyTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above: maybe omit the PyTime_CAST
to keep the diff smaller?
return call_dst(GET_TIME_TZINFO(self), Py_None); | ||
} | ||
|
||
static PyObject * | ||
time_tzname(PyDateTime_Time *self, PyObject *unused) { | ||
time_tzname(PyObject *op, PyObject *Py_UNUSED(dummy)) { | ||
PyDateTime_Time *self = PyTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above: maybe omit the PyTime_CAST
to keep the diff smaller?
{ | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
{ | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
datetime_tzname(PyObject *self, PyObject *unused) { | ||
return call_tzname(GET_DT_TZINFO(self), self); | ||
datetime_tzname(PyObject *op, PyObject *Py_UNUSED(dummy)) { | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
{ | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
{ | ||
return format_ctime((PyDateTime_Date *)self, | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
{ | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
{ | ||
PyDateTime_DateTime *self = PyDateTime_CAST(op); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DATE_GET_*
macros would not need the PyDateTime_CAST
.
The reason why I made the changes here is because the macros may be extended to static inline functions with runtime checks in the future and we definitely don't want to fill out missing pieces. For now, they don't do anything but ideally, the |
Ah! I remember what I did. I wrote a note saying that a postmerge task should be done where I eliminate the unnecessary casts in the GET macros so that we can add a check in the macro instead of in the getters. |
This PR fixes the UBSan failures and addresses some minor cosmetic changes. PEP-7 changes were not applied since they could scramble the diff but other semantic changes affecting the signature of touched functions may have been done.