diff options
author | Oren Milman <orenmn@gmail.com> | 2017-08-26 12:27:50 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-08-26 12:27:50 (GMT) |
commit | 8e67981fc8e1bf3cb9774b5fbf4a39b8d65ba4ff (patch) | |
tree | c8067ed049bd6987f5d5dd1183fff869f2dd8eaf /Modules/_io | |
parent | cb7fdf69ec9235cb358580f189089eaf575fb9df (diff) | |
download | cpython-8e67981fc8e1bf3cb9774b5fbf4a39b8d65ba4ff.zip cpython-8e67981fc8e1bf3cb9774b5fbf4a39b8d65ba4ff.tar.gz cpython-8e67981fc8e1bf3cb9774b5fbf4a39b8d65ba4ff.tar.bz2 |
[3.6] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args. (#3210)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index bc8d11e..61adcf6 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -538,6 +538,12 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self) _PyIO_str_getstate, NULL); if (state == NULL) return NULL; + if (!PyTuple_Check(state)) { + PyErr_SetString(PyExc_TypeError, + "illegal decoder state"); + Py_DECREF(state); + return NULL; + } if (!PyArg_ParseTuple(state, "OK", &buffer, &flag)) { Py_DECREF(state); return NULL; @@ -569,6 +575,10 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, PyObject *buffer; unsigned long long flag; + if (!PyTuple_Check(state)) { + PyErr_SetString(PyExc_TypeError, "state argument must be a tuple"); + return NULL; + } if (!PyArg_ParseTuple(state, "OK", &buffer, &flag)) return NULL; @@ -2320,6 +2330,12 @@ _io_TextIOWrapper_tell_impl(textio *self) _PyIO_str_getstate, NULL); \ if (_state == NULL) \ goto fail; \ + if (!PyTuple_Check(_state)) { \ + PyErr_SetString(PyExc_TypeError, \ + "illegal decoder state"); \ + Py_DECREF(_state); \ + goto fail; \ + } \ if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \ Py_DECREF(_state); \ goto fail; \ |