summaryrefslogtreecommitdiffstats
path: root/Modules/audioop.c
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-08-20 15:35:36 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-08-20 15:35:36 (GMT)
commit1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1 (patch)
treeb5d3ee0a0aba15a2586c4e891630554dd702e933 /Modules/audioop.c
parent4bfebc63012f0f4e00f6a98c3d96e1c0ebe93408 (diff)
downloadcpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.zip
cpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.tar.gz
cpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.tar.bz2
bpo-28261: Fixed err msgs where PyArg_ParseTuple is used to parse normal tuples. (#3119)
Diffstat (limited to 'Modules/audioop.c')
-rw-r--r--Modules/audioop.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/Modules/audioop.c b/Modules/audioop.c
index dcd7788..80c8a2a 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1293,7 +1293,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
char *cp, *ncp;
Py_ssize_t len;
int chan, d, *prev_i, *cur_i, cur_o;
- PyObject *samps, *str, *rv = NULL;
+ PyObject *samps, *str, *rv = NULL, *channel;
int bytes_per_frame;
if (!audioop_check_size(width))
@@ -1354,8 +1354,12 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
prev_i[chan] = cur_i[chan] = 0;
}
else {
+ if (!PyTuple_Check(state)) {
+ PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+ goto exit;
+ }
if (!PyArg_ParseTuple(state,
- "iO!;audioop.ratecv: illegal state argument",
+ "iO!;ratecv(): illegal state argument",
&d, &PyTuple_Type, &samps))
goto exit;
if (PyTuple_Size(samps) != nchannels) {
@@ -1364,10 +1368,18 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
goto exit;
}
for (chan = 0; chan < nchannels; chan++) {
- if (!PyArg_ParseTuple(PyTuple_GetItem(samps, chan),
- "ii:ratecv", &prev_i[chan],
- &cur_i[chan]))
+ channel = PyTuple_GetItem(samps, chan);
+ if (!PyTuple_Check(channel)) {
+ PyErr_SetString(PyExc_TypeError,
+ "ratecv(): illegal state argument");
goto exit;
+ }
+ if (!PyArg_ParseTuple(channel,
+ "ii;ratecv(): illegal state argument",
+ &prev_i[chan], &cur_i[chan]))
+ {
+ goto exit;
+ }
}
}
@@ -1638,7 +1650,9 @@ audioop_lin2adpcm_impl(PyObject *module, Py_buffer *fragment, int width,
PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
return NULL;
}
- else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+ else if (!PyArg_ParseTuple(state, "ii;lin2adpcm(): illegal state argument",
+ &valpred, &index))
+ {
return NULL;
}
else if (valpred >= 0x8000 || valpred < -0x8000 ||
@@ -1766,7 +1780,9 @@ audioop_adpcm2lin_impl(PyObject *module, Py_buffer *fragment, int width,
PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
return NULL;
}
- else if (!PyArg_ParseTuple(state, "ii", &valpred, &index)) {
+ else if (!PyArg_ParseTuple(state, "ii;adpcm2lin(): illegal state argument",
+ &valpred, &index))
+ {
return NULL;
}
else if (valpred >= 0x8000 || valpred < -0x8000 ||