8000 gh-111178: fix UBSan failures in `Modules/_lzmamodule.c` (GH-129783) · python/cpython@185ac5a · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 185ac5a

Browse files
authored
gh-111178: fix UBSan failures in Modules/_lzmamodule.c (GH-129783)
fix UBSan failures for LZMA objects suppress unused return values
1 parent 97d0011 commit 185ac5a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Modules/_lzmamodule.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ typedef struct {
126126
PyThread_type_lock lock;
127127
} Decompressor;
128128

129+
#define Compressor_CAST(op) ((Compressor *)(op))
130+
#define Decompressor_CAST(op) ((Decompressor *)(op))
131+
129132
/* Helper functions. */
130133

131134
static int
@@ -857,14 +860,15 @@ Compressor_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
857860
}
858861

859862
static void
860-
Compressor_dealloc(Compressor *self)
863+
Compressor_dealloc(PyObject *op)
861864
{
865+
Compressor *self = Compressor_CAST(op);
862866
lzma_end(&self->lzs);
863867
if (self->lock != NULL) {
864868
PyThread_free_lock(self->lock);
865869
}
866870
PyTypeObject *tp = Py_TYPE(self);
867-
tp->tp_free((PyObject *)self);
871+
tp->tp_free(self);
868872
Py_DECREF(tp);
869873
}
870874

@@ -875,7 +879,7 @@ static PyMethodDef Compressor_methods[] = {
875879
};
876880

877881
static int
878-
Compressor_traverse(Compressor *self, visitproc visit, void *arg)
882+
Compressor_traverse(PyObject *self, visitproc visit, void *arg)
879883
{
880884
Py_VISIT(Py_TYPE(self));
881885
return 0;
@@ -1304,8 +1308,9 @@ _lzma_LZMADecompressor_impl(PyTypeObject *type, int format,
13041308
}
13051309

13061310
static void
1307-
Decompressor_dealloc(Decompressor *self)
1311+
Decompressor_dealloc(PyObject *op)
13081312
{
1313+
Decompressor *self = Decompressor_CAST(op);
13091314
if(self->input_buffer != NULL)
13101315
PyMem_Free(self->input_buffer);
13111316

@@ -1315,12 +1320,12 @@ Decompressor_dealloc(Decompressor *self)
13151320
PyThread_free_lock(self->lock);
13161321
}
13171322
PyTypeObject *tp = Py_TYPE(self);
1318-
tp->tp_free((PyObject *)self);
1323+
tp->tp_free(self);
13191324
Py_DECREF(tp);
13201325
}
13211326

13221327
static int
1323-
Decompressor_traverse(Decompressor *self, visitproc visit, void *arg)
1328+
Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
13241329
{
13251330
Py_VISIT(Py_TYPE(self));
13261331
return 0;
@@ -1633,7 +1638,7 @@ lzma_clear(PyObject *module)
16331638
static void
16341639
lzma_free(void *module)
16351640
{
1636-
lzma_clear((PyObject *)module);
1641+
(void)lzma_clear((PyObject *)module);
16371642
}
16381643

16391644
static PyModuleDef _lzmamodule = {

0 commit comments

Comments
 (0)
0