From 9e1c192525f0382ec1e8710c2f8e1dcef389ff77 Mon Sep 17 00:00:00 2001 From: Thomas Wouters Date: Mon, 17 Mar 2003 11:24:29 +0000 Subject: 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.) --- Modules/binascii.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Modules/binascii.c') diff --git a/Modules/binascii.c b/Modules/binascii.c index c56d528ef4..05964c9351 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -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; } -- cgit v1.2.1