Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85c2497

Browse files
Issue #16404: Add checks for return value of PyLong_FromLong() in
sys.getwindowsversion() and ossaudiodev.setparameters(). Reported by Ned Batchelder.
2 parents 11ee080 + 48d761e commit 85c2497

2 files changed

Lines changed: 5 additions & 8 deletions

File tree

Modules/ossaudiodev.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
564564
{
565565
int wanted_fmt, wanted_channels, wanted_rate, strict=0;
566566
int fmt, channels, rate;
567-
PyObject * rv; /* return tuple (fmt, channels, rate) */
568567

569568
if (!_is_fd_valid(self->fd))
570569
return NULL;
@@ -609,13 +608,7 @@ oss_setparameters(oss_audio_t *self, PyObject *args)
609608

610609
/* Construct the return value: a (fmt, channels, rate) tuple that
611610
tells what the audio hardware was actually set to. */
612-
rv = PyTuple_New(3);
613-
if (rv == NULL)
614-
return NULL;
615-
PyTuple_SET_ITEM(rv, 0, PyLong_FromLong(fmt));
616-
PyTuple_SET_ITEM(rv, 1, PyLong_FromLong(channels));
617-
PyTuple_SET_ITEM(rv, 2, PyLong_FromLong(rate));
618-
return rv;
611+
return Py_BuildValue("(iii)", fmt, channels, rate);
619612
}
620613

621614
static int

Python/sysmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,10 @@ sys_getwindowsversion(PyObject *self)
801801
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wSuiteMask));
802802
PyStructSequence_SET_ITEM(version, pos++, PyLong_FromLong(ver.wProductType));
803803

804+
if (PyErr_Occurred()) {
805+
Py_DECREF(version);
806+
return NULL;
807+
}
804808
return version;
805809
}
806810

0 commit comments

Comments
 (0)