diff options
author | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:05:50 -0800 |
---|---|---|
committer | Steve Dower <steve.dower@microsoft.com> | 2017-02-04 15:05:50 -0800 |
commit | 3b0e4320092ac0504b6670cafaf0301b908c91fc (patch) | |
tree | d3be1b6b844d61763bb366fa21ceed475e5703fd /Modules/_io/bufferedio.c | |
parent | b2fa705fd3887c326e811c418469c784353027f4 (diff) | |
parent | f687fbcd73c14dfcbe086eb5cd94b298f1e81e72 (diff) | |
download | cpython-3b0e4320092ac0504b6670cafaf0301b908c91fc.tar.gz |
Issue #29392: Prevent crash when passing invalid arguments into msvcrt module.
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r-- | Modules/_io/bufferedio.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index cbe7425eae..6c88bbb2b0 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -305,7 +305,7 @@ _enter_buffered_busy(buffered *self) "could not acquire lock for %A at interpreter " "shutdown, possibly due to daemon threads", (PyObject *) self); - char *msg = PyUnicode_AsUTF8(msgobj); + const char *msg = PyUnicode_AsUTF8(msgobj); Py_FatalError(msg); } return 1; @@ -454,7 +454,8 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source); + r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn, + source, NULL); if (r) Py_DECREF(r); else @@ -904,7 +905,7 @@ _io__Buffered_read_impl(buffered *self, Py_ssize_t n) CHECK_INITIALIZED(self) if (n < -1) { PyErr_SetString(PyExc_ValueError, - "read length must be positive or -1"); + "read length must be non-negative or -1"); return NULL; } @@ -932,22 +933,20 @@ _io__Buffered_read_impl(buffered *self, Py_ssize_t n) /*[clinic input] _io._Buffered.read1 - size as n: Py_ssize_t + size as n: Py_ssize_t = -1 / [clinic start generated code]*/ static PyObject * _io__Buffered_read1_impl(buffered *self, Py_ssize_t n) -/*[clinic end generated code: output=bcc4fb4e54d103a3 input=8d2869c18b983184]*/ +/*[clinic end generated code: output=bcc4fb4e54d103a3 input=7d22de9630b61774]*/ { Py_ssize_t have, r; PyObject *res = NULL; CHECK_INITIALIZED(self) if (n < 0) { - PyErr_SetString(PyExc_ValueError, - "read length must be positive"); - return NULL; + n = self->buffer_size; } CHECK_CLOSED(self, "read of closed file") @@ -1690,8 +1689,7 @@ _bufferedreader_read_generic(buffered *self, Py_ssize_t n) return res; } Py_DECREF(res); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } remaining -= r; written += r; @@ -1715,8 +1713,7 @@ _bufferedreader_read_generic(buffered *self, Py_ssize_t n) return res; } Py_DECREF(res); - Py_INCREF(Py_None); - return Py_None; + Py_RETURN_NONE; } if (remaining > r) { memcpy(out + written, self->buffer + self->pos, r); |