php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39421 tempnam() unexpected behavior
Submitted: 2006-11-08 06:19 UTC Modified: 2006-11-08 17:16 UTC
From: ruslan_y at list dot ru Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.2.0 OS: Windows XP SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ruslan_y at list dot ru
New email:
PHP Version: OS:

 

 [2006-11-08 06:19 UTC] ruslan_y at list dot ru
Description:
------------
After the upgrade from old php 4.x to 5.2.0. Some of my web scripts stop working. One of the reason is the changes in tempnam() behavior which stop working with local path like "./dir" or "dir/" and force me to add system temporary folder to open_basedir path.

Configuration: 
Windows XP SP2 | PHP 5.2.0 | Apache 2.0.55 (+ php5apache2.dll)

P.S. php.exe works as expected (except DOCUMENT_ROOT is null) 
(php.exe -q 1.php)

Reproduce code:
---------------
<?php
if (!is_dir('2')) mkdir('2');

$tmpfname1 = tempnam('2/', "FOO");
$tmpfname2 = tempnam('./2/', "FOO");
$tmpfname3 = tempnam('2\\', "FOO");
$tmpfname4 = tempnam('.\2', "FOO");
$tmpfname5 = tempnam('C:\root\www\host2\www\2\\', "FOO");

echo '<pre>'."\n";
echo 'DOCUMENT_ROOT = '.$_SERVER['DOCUMENT_ROOT']."\n";
echo '$tmpfname1 = '.$tmpfname1."\n";
echo '$tmpfname2 = '.$tmpfname2."\n";
echo '$tmpfname3 = '.$tmpfname3."\n";
echo '$tmpfname4 = '.$tmpfname4."\n";
echo '$tmpfname5 = '.$tmpfname5."\n";
echo '</pre>'."\n";
?>

Expected result:
----------------
A new directory "2" and five files in it.

DOCUMENT_ROOT = C:/root/www/host2/www
$tmpfname1 = 2/FOOFA.tmp
$tmpfname2 = ./2/FOOFB.tmp
$tmpfname3 = 2\FOOFC.tmp
$tmpfname4 = .\2\FOOFD.tmp
$tmpfname5 = C:\root\www\host2\www\2\FOOFE.tmp

Actual result:
--------------
A new directory "2" and only one file in it. all other files in the windows temp folder.

DOCUMENT_ROOT = C:/root/www/host2/www
$tmpfname1 = C:\WINDOWS\TEMP\FOO10A.tmp
$tmpfname2 = C:\WINDOWS\TEMP\FOO10B.tmp
$tmpfname3 = C:\WINDOWS\TEMP\FOO10C.tmp
$tmpfname4 = C:\WINDOWS\TEMP\FOO10D.tmp
$tmpfname5 = C:\root\www\host2\www\2\FOO10E.tmp

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-08 16:47 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

As of PHP 5.2.0 tempnam() enforces open_basedir limit, which 
is why the temporary directory needs to be within the 
open_basedir.
 [2006-11-08 17:16 UTC] ruslan_y at list dot ru
I'm sorry, but I'm was not talking about open_basedir itself but about some changes of using local path in tempnam() function then php is an apache module!

You can see in the example that it's a really different as cli and sapi module!

(php -q 1.php)
...
$tmpfname3 = 2\FOOFC.tmp
...
and 
(http://localhost/1.php)
...
$tmpfname3 = C:\WINDOWS\TEMP\FOO10C.tmp
...

Why It so different? Why I cannot get an expected result? That's the question!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC