PHP 4.0 Bug #5509: tempnam() is not safe
| From: | alban dot hertroys at ddnh dot nl | Date: | Tue, 11 Jul 2000 15:27:09 +0000 |
| Subject: | PHP 4.0 Bug #5509: tempnam() is not safe | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-24084@lists.php.net to get a copy of this message | ||
From: alban.hertroys@ddnh.nl
Operating system: Any
PHP version: 4.0.1pl2
PHP Bug Type: Misbehaving function
Bug description: tempnam() is not safe
$filename = tempnam("/tmp", "blah");
<do all kinds of stuff that takes more than 0 seconds>
$fd = fopen($filename, "w+");
This could result in another proces on the system creating a temp-file with the same name in the
meantime, which then will be overwritten by PHP.
See man mkstemp on any UNIX for more details and the solution to the same problem (returning a file
descriptor of a newly opened temp-file instead of a filename).
It could be that PHP found a way to magically circumvent the problem, but that is not documented
anywhere I looked.