From 0981e5de3c3f46b1be649e2a5bd755cf91d0ef44 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lauri=20Kentt=C3=A4?= Date: Mon, 11 Jul 2016 12:40:05 +0300 Subject: [PATCH] base64_decode: Avoid code duplication in failures --- ext/standard/base64.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ext/standard/base64.c b/ext/standard/base64.c index d625dc0752..fb21759392 100644 --- a/ext/standard/base64.c +++ b/ext/standard/base64.c @@ -152,8 +152,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length /* fail if the padding character is second in a group (like V===) */ /* FIXME: why do we still allow invalid padding in other places in the middle of the string? */ if (i % 4 == 1) { - zend_string_free(result); - return NULL; + goto fail; } padding++; continue; @@ -172,8 +171,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length } /* fail on bad characters or if any data follows padding */ if (ch == -2 || padding) { - zend_string_free(result); - return NULL; + goto fail; } } @@ -200,6 +198,10 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length ZSTR_VAL(result)[ZSTR_LEN(result)] = '\0'; return result; + +fail: + zend_string_free(result); + return NULL; } /* }}} */ -- 2.40.0