From c8a6170754e3350afef94a542dbfa63c3d893c3b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 19 Mar 2024 14:01:41 -0500 Subject: [PATCH] spidev_module: fix writebytes segfault If the argument to writebytes was not a sequence, it would segfault because `seq` was being operated on without first checking for error. --- spidev_module.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spidev_module.c b/spidev_module.c index ad3c342..2d89714 100644 --- a/spidev_module.c +++ b/spidev_module.c @@ -184,8 +184,11 @@ SpiDev_writebytes(SpiDevObject *self, PyObject *args) return NULL; seq = PySequence_Fast(obj, "expected a sequence"); + if (!seq) + return NULL; + len = PySequence_Fast_GET_SIZE(seq); - if (!seq || len <= 0) { + if (len <= 0) { PyErr_SetString(PyExc_TypeError, wrmsg_list0); return NULL; }