php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #808 Strange/confusing output from tempnam
Submitted: 1998-10-01 19:00 UTC Modified: 1998-10-01 19:46 UTC
From: jesusmc at scripps dot edu Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.4 OS: SunOS 5.5.1 Generic sun4u sparc
Private report: No CVE-ID: None
 [1998-10-01 19:00 UTC] jesusmc at scripps dot edu
I put this info as a note to the function, including it here as a bug report just in case.

This function has an strange and potentially
dangerous behavior. When using the code:
<PRE>
<?
$listfile = tempnam("tmp","q");
echo($listfile . "\n");
?>
</PRE>
and running it with the stand-alone version
of php3, the following are the results:
(Assume that you are in dir /home/user/foo)
<OL>
<LI>If the subdir "tmp" does not exist
<PRE>
Content-type: text/html
 
/var/tmp/qAAAa001Nh
</PRE>
</LI>
<LI>If the subdir "tmp" exists
<PRE>
Content-type: text/html
 
tmp/qAAAa001Ob
</PRE>
</LI>
</OL>
The latter is the intended answer in the first place.
My impression was that the function returns a unique
filename, so I fail to see the advantage of making it
search through the filesystem or the path var.
<P>
Now, if you change the first line of the code to read:
<PRE>
$listfile = tempnam("./tmp","q");
</PRE>
You get the same behavior as the previous 2 cases, but if
you use:
<PRE>
$listfile = tempnam("","q");
</PRE>
The results is:
<PRE>
Content-type: text/html
 
/var/tmp/qAAAa001PI
</PRE>
No matter if subdir "tmp" exists or not, when the expected
output will be a unique filename w/o directory path.
<P>
This is useful because this temp filename will be used to create
a file in different directories, depending on the values of
one or more variables from a form.
<P>
This behavior should be (a) fixed or (b) documented clearly. I did
not see this mentioned in the PHP/FI manual either.

=== Extra info ===

PHP was compiled with a command line like:
./configure --prefix=/foo/bar/php3 --without-gd --with-msql=/foo/bar/mSQL --with-config-file-path=/foo/bar/php3 
--enable-track-vars --enable-magic-quotes --with-apache=/foo/bar/src/apache_1.3.1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-10-01 19:46 UTC] rasmus
PHP's tempnam() function is simply a frontend to the standard libc tempnam() function.  Check your system's tempnam man page for more info.  You can use tempnam() to generate a unique filename that can be used anywhere in the filesystem.  It is only unique to the directory that was used when it was created.  If you want a system-wide unique string see the uniqid() function.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 10:01:32 2024 UTC