base64_decode: Avoid code duplication in failures

This commit is contained in:
Lauri Kenttä 2016-07-11 12:40:05 +03:00 committed by Nikita Popov
parent 7a02704c0e
commit 0981e5de3c

View file

@ -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;
}
/* }}} */