diff options
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r-- | Modules/binascii.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 689d132..01e8860 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -537,6 +537,7 @@ PyDoc_STRVAR(doc_a2b_hqx, "ascii -> bin, done. Decode .hqx coding"); static PyObject * binascii_a2b_hqx(PyObject *self, PyObject *args) { + Py_buffer pascii; unsigned char *ascii_data, *bin_data; int leftbits = 0; unsigned char this_ch; @@ -545,19 +546,25 @@ binascii_a2b_hqx(PyObject *self, PyObject *args) Py_ssize_t len; int done = 0; - if ( !PyArg_ParseTuple(args, "t#:a2b_hqx", &ascii_data, &len) ) + if ( !PyArg_ParseTuple(args, "y*:a2b_hqx", &pascii) ) return NULL; + ascii_data = pascii.buf; + len = pascii.len; assert(len >= 0); - if (len > PY_SSIZE_T_MAX - 2) + if (len > PY_SSIZE_T_MAX - 2) { + PyBuffer_Release(&pascii); return PyErr_NoMemory(); + } /* Allocate a string that is too big (fixed later) Add two to the initial length to prevent interning which would preclude subsequent resizing. */ - if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL ) + if ( (rv=PyBytes_FromStringAndSize(NULL, len+2)) == NULL ) { + PyBuffer_Release(&pascii); return NULL; + } bin_data = (unsigned char *)PyBytes_AS_STRING(rv); for( ; len > 0 ; len--, ascii_data++ ) { @@ -567,6 +574,7 @@ binascii_a2b_hqx(PyObject *self, PyObject *args) continue; if ( this_ch == FAIL ) { PyErr_SetString(Error, "Illegal char"); + PyBuffer_Release(&pascii); Py_DECREF(rv); return NULL; } @@ -589,6 +597,7 @@ binascii_a2b_hqx(PyObject *self, PyObject *args) if ( leftbits && !done ) { PyErr_SetString(Incomplete, "String has incomplete number of bytes"); + PyBuffer_Release(&pascii); Py_DECREF(rv); return NULL; } @@ -600,10 +609,12 @@ binascii_a2b_hqx(PyObject *self, PyObject *args) } if (rv) { PyObject *rrv = Py_BuildValue("Oi", rv, done); + PyBuffer_Release(&pascii); Py_DECREF(rv); return rrv; } + PyBuffer_Release(&pascii); return NULL; } @@ -739,7 +750,7 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args) PyObject *rv; Py_ssize_t in_len, out_len, out_len_left; - if ( !PyArg_ParseTuple(args, "s*:rledecode_hqx", &pin) ) + if ( !PyArg_ParseTuple(args, "y*:rledecode_hqx", &pin) ) return NULL; in_data = pin.buf; in_len = pin.len; @@ -1110,7 +1121,7 @@ binascii_unhexlify(PyObject *self, PyObject *args) char* retbuf; Py_ssize_t i, j; - if (!PyArg_ParseTuple(args, "s*:a2b_hex", &parg)) + if (!PyArg_ParseTuple(args, "y*:a2b_hex", &parg)) return NULL; argbuf = parg.buf; arglen = parg.len; @@ -1188,7 +1199,7 @@ binascii_a2b_qp(PyObject *self, PyObject *args, PyObject *kwargs) static char *kwlist[] = {"data", "header", NULL}; int header = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|i", kwlist, &pdata, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i", kwlist, &pdata, &header)) return NULL; data = pdata.buf; @@ -1326,8 +1337,7 @@ binascii_b2a_qp (PyObject *self, PyObject *args, PyObject *kwargs) ((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) || ((data[in] < 33) && (data[in] != '\r') && (data[in] != '\n') && - (quotetabs || - (!quotetabs && ((data[in] != '\t') && (data[in] != ' ')))))) + (quotetabs || ((data[in] != '\t') && (data[in] != ' '))))) { if ((linelen + 3) >= MAXLINESIZE) { linelen = 0; |