php-5.3.7のcryptのバグ
5.3.7 upgrade warning
[22-Aug-2011]
http://www.php.net/archive/2011.php#id2011-08-22-1
Due to unfortunate issues with 5.3.7 (see bug#55439) users should wait with upgrading until 5.3.8 will be released (expected in few days).
となっていてリンク先のバグをみると
If crypt() is executed with MD5 salts, the return value conists of the salt only.
https://bugs.php.net/bug.php?id=55439
DES and BLOWFISH salts work as expected.
MD5でcryptかけてもソルトだけを返すようになっているらしい。ので、
- php-5.3.7のcryptでソルト付きハッシュを保存すると、ソルトのみ保存される
- その状態で$pass == crypt($plain, $pass)とかやると右辺も左辺もソルトのみになるので常に真
となるっぽいな。
subversion上では修正されていて、diffをみると
$ svn diff -r 315170:315218 Index: ext/standard/php_crypt_r.c =================================================================== --- ext/standard/php_crypt_r.c (revision 315170) +++ ext/standard/php_crypt_r.c (revision 315218) @@ -382,7 +382,7 @@ /* Now make the output string */ memcpy(passwd, MD5_MAGIC, MD5_MAGIC_LEN); strlcpy(passwd + MD5_MAGIC_LEN, sp, sl + 1); - strlcat(passwd, "$", 1); + strcat(passwd, "$"); PHP_MD5Final(final, &ctx);
strlcatの仕様を勘違いしていたっぽい