mirror of
https://github.com/python/cpython.git
synced 2025-12-31 12:33:28 +00:00
gh-111178: fix UBSan failures in Modules/posixmodule.c (GH-129788)
Fix UBSan failures for `DirEntry`, `ScandirIterator` Use better semantic naming
This commit is contained in:
parent
c070abadb2
commit
de13293d26
1 changed files with 31 additions and 20 deletions
|
|
@ -8256,13 +8256,13 @@ os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
os_sched_param_reduce(PyObject *self, PyObject *Py_UNUSED(dummy))
|
||||
{
|
||||
return Py_BuildValue("(O(N))", Py_TYPE(self), PyStructSequence_GetItem(self, 0));
|
||||
}
|
||||
|
||||
static PyMethodDef os_sched_param_reduce_method = {
|
||||
"__reduce__", (PyCFunction)os_sched_param_reduce, METH_NOARGS|METH_COEXIST, NULL,
|
||||
"__reduce__", os_sched_param_reduce, METH_NOARGS | METH_COEXIST, NULL,
|
||||
};
|
||||
|
||||
PyDoc_VAR(os_sched_param__doc__);
|
||||
|
|
@ -15584,9 +15584,12 @@ typedef struct {
|
|||
#endif
|
||||
} DirEntry;
|
||||
|
||||
#define DirEntry_CAST(op) ((DirEntry *)(op))
|
||||
|
||||
static void
|
||||
DirEntry_dealloc(DirEntry *entry)
|
||||
DirEntry_dealloc(PyObject *op)
|
||||
{
|
||||
DirEntry *entry = DirEntry_CAST(op);
|
||||
PyTypeObject *tp = Py_TYPE(entry);
|
||||
Py_XDECREF(entry->name);
|
||||
Py_XDECREF(entry->path);
|
||||
|
|
@ -15915,8 +15918,9 @@ os_DirEntry_inode_impl(DirEntry *self)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
DirEntry_repr(DirEntry *self)
|
||||
DirEntry_repr(PyObject *op)
|
||||
{
|
||||
DirEntry *self = DirEntry_CAST(op);
|
||||
return PyUnicode_FromFormat("<DirEntry %R>", self->name);
|
||||
}
|
||||
|
||||
|
|
@ -16179,6 +16183,8 @@ typedef struct {
|
|||
#endif
|
||||
} ScandirIterator;
|
||||
|
||||
#define ScandirIterator_CAST(op) ((ScandirIterator *)(op))
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
|
||||
static int
|
||||
|
|
@ -16202,8 +16208,9 @@ ScandirIterator_closedir(ScandirIterator *iterator)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
ScandirIterator_iternext(ScandirIterator *iterator)
|
||||
ScandirIterator_iternext(PyObject *op)
|
||||
{
|
||||
ScandirIterator *iterator = ScandirIterator_CAST(op);
|
||||
WIN32_FIND_DATAW *file_data = &iterator->file_data;
|
||||
BOOL success;
|
||||
PyObject *entry;
|
||||
|
|
@ -16273,8 +16280,9 @@ ScandirIterator_closedir(ScandirIterator *iterator)
|
|||
}
|
||||
|
||||
static PyObject *
|
||||
ScandirIterator_iternext(ScandirIterator *iterator)
|
||||
ScandirIterator_iternext(PyObject *op)
|
||||
{
|
||||
ScandirIterator *iterator = ScandirIterator_CAST(op);
|
||||
struct dirent *direntp;
|
||||
Py_ssize_t name_len;
|
||||
int is_dot;
|
||||
|
|
@ -16326,37 +16334,40 @@ ScandirIterator_iternext(ScandirIterator *iterator)
|
|||
#endif
|
||||
|
||||
static PyObject *
|
||||
ScandirIterator_close(ScandirIterator *self, PyObject *args)
|
||||
ScandirIterator_close(PyObject *op, PyObject *Py_UNUSED(dummy))
|
||||
{
|
||||
ScandirIterator *self = ScandirIterator_CAST(op);
|
||||
ScandirIterator_closedir(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ScandirIterator_enter(PyObject *self, PyObject *args)
|
||||
ScandirIterator_enter(PyObject *self, PyObject *Py_UNUSED(dummy))
|
||||
{
|
||||
return Py_NewRef(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ScandirIterator_exit(ScandirIterator *self, PyObject *args)
|
||||
ScandirIterator_exit(PyObject *op, PyObject *Py_UNUSED(args))
|
||||
{
|
||||
ScandirIterator *self = ScandirIterator_CAST(op);
|
||||
ScandirIterator_closedir(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
ScandirIterator_finalize(ScandirIterator *iterator)
|
||||
ScandirIterator_finalize(PyObject *op)
|
||||
{
|
||||
|
||||
ScandirIterator *iterator = ScandirIterator_CAST(op);
|
||||
/* Save the current exception, if any. */
|
||||
PyObject *exc = PyErr_GetRaisedException();
|
||||
|
||||
if (!ScandirIterator_is_closed(iterator)) {
|
||||
ScandirIterator_closedir(iterator);
|
||||
|
||||
if (PyErr_ResourceWarning((PyObject *)iterator, 1,
|
||||
"unclosed scandir iterator %R", iterator)) {
|
||||
if (PyErr_ResourceWarning(op, 1,
|
||||
"unclosed scandir iterator %R", iterator))
|
||||
{
|
||||
/* Spurious errors can appear at shutdown */
|
||||
if (PyErr_ExceptionMatches(PyExc_Warning)) {
|
||||
PyErr_FormatUnraisable("Exception ignored while finalizing "
|
||||
|
|
@ -16372,21 +16383,21 @@ ScandirIterator_finalize(ScandirIterator *iterator)
|
|||
}
|
||||
|
||||
static void
|
||||
ScandirIterator_dealloc(ScandirIterator *iterator)
|
||||
ScandirIterator_dealloc(PyObject *op)
|
||||
{
|
||||
PyTypeObject *tp = Py_TYPE(iterator);
|
||||
if (PyObject_CallFinalizerFromDealloc((PyObject *)iterator) < 0)
|
||||
PyTypeObject *tp = Py_TYPE(op);
|
||||
if (PyObject_CallFinalizerFromDealloc(op) < 0)
|
||||
return;
|
||||
|
||||
freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
|
||||
free_func(iterator);
|
||||
free_func(op);
|
||||
Py_DECREF(tp);
|
||||
}
|
||||
|
||||
static PyMethodDef ScandirIterator_methods[] = {
|
||||
{"__enter__", (PyCFunction)ScandirIterator_enter, METH_NOARGS},
|
||||
{"__exit__", (PyCFunction)ScandirIterator_exit, METH_VARARGS},
|
||||
{"close", (PyCFunction)ScandirIterator_close, METH_NOARGS},
|
||||
{"__enter__", ScandirIterator_enter, METH_NOARGS},
|
||||
{"__exit__", ScandirIterator_exit, METH_VARARGS},
|
||||
{"close", ScandirIterator_close, METH_NOARGS},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue