Skip to content

Commit c5e1131

Browse files
[3.13] gh-111178: fix UBSan failures in Modules/_multiprocessing/semaphore.c (GH-129084) (#129100)
gh-111178: fix UBSan failures in `Modules/_multiprocessing/semaphore.c` (GH-129084) fix UBSan failures for `SemLockObject` (cherry picked from commit 5ed5572) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 2077082 commit c5e1131

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Modules/_multiprocessing/semaphore.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ typedef struct {
2727
char *name;
2828
} SemLockObject;
2929

30+
#define _SemLockObject_CAST(op) ((SemLockObject *)(op))
31+
3032
/*[python input]
3133
class SEM_HANDLE_converter(CConverter):
3234
type = "SEM_HANDLE"
@@ -575,8 +577,9 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
575577
}
576578

577579
static void
578-
semlock_dealloc(SemLockObject* self)
580+
semlock_dealloc(PyObject *op)
579581
{
582+
SemLockObject *self = _SemLockObject_CAST(op);
580583
PyTypeObject *tp = Py_TYPE(self);
581584
PyObject_GC_UnTrack(self);
582585
if (self->handle != SEM_FAILED)
@@ -717,7 +720,7 @@ _multiprocessing_SemLock___exit___impl(SemLockObject *self,
717720
}
718721

719722
static int
720-
semlock_traverse(SemLockObject *s, visitproc visit, void *arg)
723+
semlock_traverse(PyObject *s, visitproc visit, void *arg)
721724
{
722725
Py_VISIT(Py_TYPE(s));
723726
return 0;

0 commit comments

Comments
 (0)