com php-src: base64_decode: reorder to fix out of bounds read: ext/standard/base64.c

From: Date: Tue, 05 Jul 2016 14:51:36 +0000
Subject: com php-src: base64_decode: reorder to fix out of bounds read: ext/standard/base64.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92821@lists.php.net to get a copy of this message
Commit: 59d36bfcf2b3241843883f6f728e1b93224df12a Author: Lauri Kenttä <lauri.kentta@gmail.com> Wed, 25 May 2016 20:28:45 +0300 Committer: Nikita Popov <nikic@php.net> Tue, 5 Jul 2016 16:51:36 +0200 Parents: f22bc6438dcaf55bf80e7be972f3374d31dbaae5 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=59d36bfcf2b3241843883f6f728e1b93224df12a Log: base64_decode: reorder to fix out of bounds read Changed paths: M ext/standard/base64.c Diff: diff --git a/ext/standard/base64.c b/ext/standard/base64.c index 81f826c..352e7ea 100644 --- a/ext/standard/base64.c +++ b/ext/standard/base64.c @@ -143,16 +143,19 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length result = zend_string_alloc(length, 0); /* run through the whole string, converting as we go */ - while ((ch = *current++) != '\0' && length-- > 0) { + while (length-- > 0 && (ch = *current++) != '\0') { if (ch == base64_pad) { - if (*current != '=' && ((i % 4) == 1 || (strict && length > 0))) { - if ((i % 4) != 1) { - while (isspace(*(++current))) { - continue; - } - if (*current == '\0') { - continue; - } + if (i % 4 == 1) { + if (length == 0 || *current != '=') { + zend_string_free(result); + return NULL; + } + } else if (length > 0 && *current != '=' && strict) { + while (--length > 0 && isspace(*++current)) { + continue; + } + if (length == 0 || *current == '\0') { + continue; } zend_string_free(result); return NULL;

« previous php.cvs (#92821) next »