Re: com php-src: Fixed bug #69686 password_verify reports back error on PHP7 will null string.: NEWS ext/standard/crypt.c ext/standard/password.c
ext/standard/php_crypt.h ext/standard/tests/password/password_verify.phpt

From: Date: Thu, 21 May 2015 22:22:29 +0000
Subject: Re: com php-src: Fixed bug #69686 password_verify reports back error on PHP7 will null string.: NEWS ext/standard/crypt.c ext/standard/password.c
ext/standard/php_crypt.h ext/standard/tests/password/password_verify.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-86865@lists.php.net to get a copy of this message
Hi Anthony, Error for too long password against blowfish hash? The same approach, ignore error, can be used for invalid too long password also. -- Yasuo Ohgaki yohgaki@ohgaki.net On Fri, May 22, 2015 at 6:12 AM, Anthony Ferrara <ircmaxell@php.net> wrote: > Commit: ed4052f1d5309cc974b134c2b78724d727ef9349 > Author: Anthony Ferrara <ircmaxell@gmail.com> Thu, 21 May 2015 > 17:12:51 -0400 > Parents: 3dba00bc31eb92ef1187f6dd78f2c7bb3c003710 > Branches: master > > Link: > > http://git.php.net/?p=php-src.git;a=commitdiff;h=ed4052f1d5309cc974b134c2b78724d727ef9349 > > Log: > Fixed bug #69686 password_verify reports back error on PHP7 will null > string. > > The deprecation of DES salts created a warning when trying to verify them > with password_hash. This bug fix adds a quiet mode to php_crypt() which is > used by password_verify. > > Bugs: > https://bugs.php.net/69686 > > Changed paths: > M NEWS > M ext/standard/crypt.c > M ext/standard/password.c > M ext/standard/php_crypt.h > M ext/standard/tests/password/password_verify.phpt > > > Diff: > diff --git a/NEWS b/NEWS > index 035cff9..162cdf9 100644 > --- a/NEWS > +++ b/NEWS > @@ -221,7 +221,9 @@ > . Fixed bug #65272 (flock() out parameter not set correctly in windows). > (Daniel Lowrey) > . Added preg_replace_callback_array function. (Wei Dai) > - . Deprecated salt option to password_hash. (Anthony) > + . Deprecated salt option to password_hash. (Anthony) > + . Fixed bug #69686 (password_verify reports back error on PHP7 will null > + string). (Anthony) > . Added Windows support for getrusage(). (Kalle) > > - Streams: > diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c > index da51ee9..74ab291 100644 > --- a/ext/standard/crypt.c > +++ b/ext/standard/crypt.c > @@ -151,7 +151,7 @@ static void php_to64(char *s, zend_long v, int n) /* > {{{ */ > } > /* }}} */ > > -PHPAPI zend_string *php_crypt(const char *password, const int pass_len, > const char *salt, int salt_len) > +PHPAPI zend_string *php_crypt(const char *password, const int pass_len, > const char *salt, int salt_len, zend_bool quiet) > { > char *crypt_res; > zend_string *result; > @@ -225,7 +225,10 @@ PHPAPI zend_string *php_crypt(const char *password, > const int pass_len, const ch > if (salt[0] != '_') { > /* DES style hashes */ > if (!IS_VALID_SALT_CHARACTER(salt[0]) || > !IS_VALID_SALT_CHARACTER(salt[1])) { > - php_error_docref(NULL, > E_DEPRECATED, DES_INVALID_SALT_ERROR); > + if (!quiet) { > + /* error consistently > about invalid DES fallbacks */ > + php_error_docref(NULL, > E_DEPRECATED, DES_INVALID_SALT_ERROR); > + } > } > } > > @@ -254,8 +257,10 @@ PHPAPI zend_string *php_crypt(const char *password, > const int pass_len, const ch > # error Data struct used by crypt_r() is unknown. Please report. > # endif > if (salt[0] != '$' && salt[0] != '_' && > (!IS_VALID_SALT_CHARACTER(salt[0]) || !IS_VALID_SALT_CHARACTER(salt[1]))) { > - /* error consistently about invalid DES fallbacks > */ > - php_error_docref(NULL, E_DEPRECATED, > DES_INVALID_SALT_ERROR); > + if (!quiet) { > + /* error consistently about invalid DES > fallbacks */ > + php_error_docref(NULL, E_DEPRECATED, > DES_INVALID_SALT_ERROR); > + } > } > crypt_res = crypt_r(password, salt, &buffer); > if (!crypt_res || (salt[0] == '*' && salt[1] == > '0')) { > @@ -313,7 +318,7 @@ PHP_FUNCTION(crypt) > } > salt[salt_in_len] = '\0'; > > - if ((result = php_crypt(str, (int)str_len, salt, > (int)salt_in_len)) == NULL) { > + if ((result = php_crypt(str, (int)str_len, salt, (int)salt_in_len, > 0)) == NULL) { > if (salt[0] == '*' && salt[1] == '0') { > RETURN_STRING("*1"); > } else { > diff --git a/ext/standard/password.c b/ext/standard/password.c > index 209e253..4ad955e 100644 > --- a/ext/standard/password.c > +++ b/ext/standard/password.c > @@ -260,7 +260,7 @@ PHP_FUNCTION(password_verify) > if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &password, > &password_len, &hash, &hash_len) == FAILURE) { > RETURN_FALSE; > } > - if ((ret = php_crypt(password, (int)password_len, hash, > (int)hash_len)) == NULL) { > + if ((ret = php_crypt(password, (int)password_len, hash, > (int)hash_len, 1)) == NULL) { > RETURN_FALSE; > } > > @@ -415,7 +415,7 @@ PHP_FUNCTION(password_hash) > /* This cast is safe, since both values are defined here in code > and cannot overflow */ > hash_len = (int) (hash_format_len + salt_len); > > - if ((result = php_crypt(password, (int)password_len, hash, > hash_len)) == NULL) { > + if ((result = php_crypt(password, (int)password_len, hash, > hash_len, 1)) == NULL) { > efree(hash); > RETURN_FALSE; > } > diff --git a/ext/standard/php_crypt.h b/ext/standard/php_crypt.h > index d77180b..88368c9 100644 > --- a/ext/standard/php_crypt.h > +++ b/ext/standard/php_crypt.h > @@ -23,7 +23,7 @@ > #ifndef PHP_CRYPT_H > #define PHP_CRYPT_H > > -PHPAPI zend_string *php_crypt(const char *password, const int pass_len, > const char *salt, int salt_len); > +PHPAPI zend_string *php_crypt(const char *password, const int pass_len, > const char *salt, int salt_len, zend_bool quiet); > PHP_FUNCTION(crypt); > #if HAVE_CRYPT > PHP_MINIT_FUNCTION(crypt); > diff --git a/ext/standard/tests/password/password_verify.phpt > b/ext/standard/tests/password/password_verify.phpt > index e7ecc7e..a196763 100644 > --- a/ext/standard/tests/password/password_verify.phpt > +++ b/ext/standard/tests/password/password_verify.phpt > @@ -11,6 +11,13 @@ var_dump(password_verify("foo", > '$2a$07$usesomesillystringforsalt$')); > var_dump(password_verify('rasmusler', > '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi')); > > var_dump(password_verify('rasmuslerdorf', > '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi')); > + > +var_dump(password_verify("foo", null)); > + > +var_dump(password_verify("rasmuslerdorf", "rl.3StKT.4T8M")); > + > +var_dump(password_verify("foo", "$1")); > + > echo "OK!"; > ?> > --EXPECT-- > @@ -18,4 +25,7 @@ bool(false) > bool(false) > bool(false) > bool(true) > +bool(false) > +bool(true) > +bool(false) > OK! > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.cvs (#86865) next »