Skip to content

Commit 9b335cc

Browse files
[3.12] gh-111178: fix UBSan failures in Modules/_multiprocessing/semaphore.c (GH-129084) (#129101)
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 03bce18 commit 9b335cc

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
@@ -23,6 +23,8 @@ typedef struct {
2323
char *name;
2424
} SemLockObject;
2525

26+
#define _SemLockObject_CAST(op) ((SemLockObject *)(op))
27+
2628
/*[python input]
2729
class SEM_HANDLE_converter(CConverter):
2830
type = "SEM_HANDLE"
@@ -567,8 +569,9 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
567569
}
568570

569571
static void
570-
semlock_dealloc(SemLockObject* self)
572+
semlock_dealloc(PyObject *op)
571573
{
574+
SemLockObject *self = _SemLockObject_CAST(op);
572575
PyTypeObject *tp = Py_TYPE(self);
573576
PyObject_GC_UnTrack(self);
574577
if (self->handle != SEM_FAILED)
@@ -706,7 +709,7 @@ _multiprocessing_SemLock___exit___impl(SemLockObject *self,
706709
}
707710

708711
static int
709-
semlock_traverse(SemLockObject *s, visitproc visit, void *arg)
712+
semlock_traverse(PyObject *s, visitproc visit, void *arg)
710713
{
711714
Py_VISIT(Py_TYPE(s));
712715
return 0;

0 commit comments

Comments
 (0)