com php-src: Fixed bug #75221 (Argon2i always throws NUL at the end): NEWS ext/standard/password.c ext/standard/tests/password/bug75221.phpt

From: Date: Thu, 12 Oct 2017 10:52:37 +0000
Subject: com php-src: Fixed bug #75221 (Argon2i always throws NUL at the end): NEWS ext/standard/password.c ext/standard/tests/password/bug75221.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-99723@lists.php.net to get a copy of this message
Commit: 3f8961dfac96a992df2516c0e383e6820eedd31b Author: Christoph M. Becker <cmbecker69@gmx.de> Mon, 18 Sep 2017 18:09:53 +0200 Parents: ee3650742389883f0f3e4d4d009c236dab13bb7d Branches: PHP-7.2 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3f8961dfac96a992df2516c0e383e6820eedd31b Log: Fixed bug #75221 (Argon2i always throws NUL at the end) Apparently, argon2_encodedlen() also counts the terminating NUL byte; that doesn't appear to be documented somewhere, but from looking at the implementation[1] it is pretty obvious. Therefore, the respective zend_string has to be one byte shorter. [1] <https://github.com/P-H-C/phc-winner-argon2/blob/20161029/src/argon2..c#L431-L436> Bugs: https://bugs.php.net/75221 Changed paths: M NEWS M ext/standard/password.c A ext/standard/tests/password/bug75221.phpt Diff: diff --git a/NEWS b/NEWS index cfa129b...8578801 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ PHP NEWS - Openssl: . Fixed bug #75363 (openssl_x509_parse leaks memory). (Bob) +- Standard: + . Fixed bug #75221 (Argon2i always throws NUL at the end). (cmb) + - Zlib: . Fixed bug #75299 (Wrong reflection on inflate_init and inflate_add). (Fabien Villepinte) diff --git a/ext/standard/password.c b/ext/standard/password.c index 680eed4..7f99f21 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -526,7 +526,7 @@ PHP_FUNCTION(password_hash) #endif ); - encoded = zend_string_alloc(encoded_len, 0); + encoded = zend_string_alloc(encoded_len - 1, 0); status = argon2_hash( time_cost, memory_cost, @@ -538,7 +538,7 @@ PHP_FUNCTION(password_hash) ZSTR_VAL(out), ZSTR_LEN(out), ZSTR_VAL(encoded), - ZSTR_LEN(encoded), + encoded_len, type, ARGON2_VERSION_NUMBER ); diff --git a/ext/standard/tests/password/bug75221.phpt b/ext/standard/tests/password/bug75221.phpt new file mode 100644 index 0000000..ec03f92 --- /dev/null +++ b/ext/standard/tests/password/bug75221.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #75221 (Argon2i always throws NUL at the end) +--SKIPIF-- +<?php +if (!defined('PASSWORD_ARGON2I')) die('skip password_hash not built with Argon2'); +?> +--FILE-- +<?php +$hash = password_hash( + "php", + PASSWORD_ARGON2I, + ['memory_cost' => 16384, 'time_cost' => 2, 'threads' => 4] +); +var_dump(substr($hash, -1, 1) !== "\0"); +?> +===DONE=== +--EXPECT-- +bool(true) +===DONE===

« previous php.cvs (#99723) next »