summaryrefslogtreecommitdiff
path: root/ext/standard/base64.c
diff options
context:
space:
mode:
authorLauri Kenttä <lauri.kentta@gmail.com>2016-07-11 12:40:05 +0300
committerNikita Popov <nikic@php.net>2016-07-22 18:03:55 +0200
commit0981e5de3c3f46b1be649e2a5bd755cf91d0ef44 (patch)
treea050865fd1567922a2a701a2b192d87f11611917 /ext/standard/base64.c
parent7a02704c0ecdf4373c810760e70a424841619e0c (diff)
downloadphp-git-0981e5de3c3f46b1be649e2a5bd755cf91d0ef44.tar.gz
base64_decode: Avoid code duplication in failures
Diffstat (limited to 'ext/standard/base64.c')
-rw-r--r--ext/standard/base64.c10
1 files 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;
}
/* }}} */