mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
binascii_a2b_base64: Properly return an empty string if the input was all
invalid, rather than returning a string of random garbage of the estimated result length. Closes SF patch #703471 by Hye-Shik Chang. Will backport to 2.2-maint (consider it done.)
This commit is contained in:
parent
450bd873ac
commit
9e1c192525
2 changed files with 12 additions and 1 deletions
|
@ -408,9 +408,16 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* and set string size correctly */
|
||||
/* And set string size correctly. If the result string is empty
|
||||
** (because the input was all invalid) return the shared empty
|
||||
** string instead; _PyString_Resize() won't do this for us.
|
||||
*/
|
||||
if (bin_len > 0)
|
||||
_PyString_Resize(&rv, bin_len);
|
||||
else {
|
||||
Py_DECREF(rv);
|
||||
rv = PyString_FromString("");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue