]> granicus.if.org Git - php/commitdiff
base64_decode: remove redundant check
authorLauri Kenttä <lauri.kentta@gmail.com>
Wed, 25 May 2016 18:15:52 +0000 (21:15 +0300)
committerNikita Popov <nikic@php.net>
Tue, 5 Jul 2016 14:51:36 +0000 (16:51 +0200)
If length == 0 || *current != '=' is false, the for loop will always
end up in this same point, until the if statement becomes true.
Thus, the if statement is not needed.

ext/standard/base64.c

index 352e7ea52c966acbde4bcb2851aa9a48ad67bfec..e8d7f04aa4ef1e69ba1f2afa25594d4167800438 100644 (file)
@@ -145,12 +145,13 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length
        /* run through the whole string, converting as we go */
        while (length-- > 0 && (ch = *current++) != '\0') {
                if (ch == base64_pad) {
+                       /* 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) {
-                               if (length == 0 || *current != '=') {
-                                       zend_string_free(result);
-                                       return NULL;
-                               }
-                       } else if (length > 0 && *current != '=' && strict) {
+                               zend_string_free(result);
+                               return NULL;
+                       }
+                       if (length > 0 && *current != '=' && strict) {
                                while (--length > 0 && isspace(*++current)) {
                                        continue;
                                }