水無月ばけらのえび日記

bakera.jp > 水無月ばけらのえび日記 > cryptがsaltしか返さないバグ・解説

cryptがsaltしか返さないバグ・解説

2011年8月24日(水曜日)

cryptがsaltしか返さないバグ・解説

公開: 2011年8月28日0時15分頃

PHPのcryptバグ原因について徳丸さんが解説されています……「PHP5.3.7のcrypt関数のバグはこうして生まれた (blog.tokumaru.org)」。

strcatは文字列の末尾に文字列を連結する関数ですが、バッファの長さを気にしないので、使い方を誤るとバッファオーバーランの原因になる可能性があります。そのため、strcatを使っているとコード解析ツールで警告される場合があります。それを嫌ってstrncatに修正し、さらにstrlcatに変更したところでバグが入ってしまったということですね。

この修正を行ったのはPHPの創始者であるRasmus Lerdorf (ja.wikipedia.org)本人で、Google+でコメントされています。興味深いのはこのあたり。

The crypt change did trigger a test to fail, we just went a bit too fast with the release and didn't notice the failure. This is mostly because we have too many test failures which is primarily caused by us adding tests for bug reports before actually fixing the bug.

以上、Rasmus Lerdorf - Google+ - If you are using crypt() in your code you might want to… より

テストに失敗していたのに、普段からテストが通らない状態だったから気にならなかったということのようで。無視しても良い警告が常に出る状態になると、警告を無視する癖がついてしまって警告が形骸化します。それが、今回のバグ版がリリースされてしまった要因の一つと言えるでしょう。

コメントには続きがあり、

I still like the practice of adding test cases for bugs and then working towards making the tests pass, however for some of these non-critical bugs that are taking a while to change we should probably switch them to XFAIL (expected fail) so they don't clutter up the test failure output and thus making it harder to spot new failures like this crypt one.

以上、Rasmus Lerdorf - Google+ - If you are using crypt() in your code you might want to… より

ということで、今後は予期された失敗を別のステータスにして区別するようですね。

関連する話題: セキュリティ / PHP / ユーザビリティ

最近の日記

関わった本など