From a9e9bbf452fc364b13bc68c340004284678e4527 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Laignel?= Date: Sun, 7 Mar 2021 20:00:19 +0100 Subject: [PATCH] alsaseq: fix 'ext' buffer fill MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The `GETDICTEXT` macro used to perfom one pass on the provided int list to check the actual item types brefore allocating and filling the target buffer. The python list was not read again causing the buffer to be filled with the last value read during the type check. This patch performs the type check as well as buffer fill in one go. The buffer is freed if an item is found to be of a wrong type. Fixes: https://github.com/alsa-project/alsa-python/pull/3 Signed-off-by: François Laignel Signed-off-by: Jaroslav Kysela --- pyalsa/alsaseq.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pyalsa/alsaseq.c b/pyalsa/alsaseq.c index e3b76a2..b2959fb 100644 --- a/pyalsa/alsaseq.c +++ b/pyalsa/alsaseq.c @@ -251,6 +251,13 @@ int len = PyList_Size(list); \ self->event->data.ext.len = len; \ if (len > 0) { \ + self->buff = malloc(len); \ + if (self->buff == NULL) { \ + PyErr_SetString(PyExc_TypeError, \ + name " no memory"); \ + self->event->data.ext.len = 0; \ + return NULL; \ + } \ int i; \ long val; \ for (i = 0; i < len; i++) { \ @@ -259,18 +266,12 @@ PyErr_SetString(PyExc_TypeError, \ name " must be a list of integers"); \ self->event->data.ext.len = 0; \ - return NULL; \ + free(self->buff); \ + self->buff = NULL; \ + return NULL; \ } \ - } \ - self->buff = malloc(len); \ - if (self->buff == NULL) { \ - PyErr_SetString(PyExc_TypeError, \ - name " no memory"); \ - self->event->data.ext.len = 0; \ - return NULL; \ - } \ - for (i = 0; i < len; i++) \ self->buff[i] = val; \ + } \ self->event->data.ext.ptr = self->buff; \ } \ } \ -- 2.47.1