#44222 [Opn]: tempnam $prefix parameter limitation

2008-03-06 Thread c dot d dot brengel at att dot net
 ID:   44222
 User updated by:  c dot d dot brengel at att dot net
 Reported By:  c dot d dot brengel at att dot net
 Status:   Open
 Bug Type: Filesystem function related
 Operating System: Windows XP
 PHP Version:  5.2.5
 New Comment:

Thank You.  I just needed to know if was a problem with my system, PHP
or Windows.  Thank You for confirming it is a Windows problem.

I have used another work around so I do not need to use tempnam.

It would be a good idea to update the PHP documentation to let others
know of this behavior on WIndows.  

Keep up the good work


Previous Comments:


[2008-03-06 23:08:23] a dot u dot savchuk at gmail dot com

As i understand it is not bug but described behavior of windows
GetTempFileName() function.
So it is not possible to fix that (in easy manner).

From MSDN http://msdn2.microsoft.com/en-us/library/aa364991.aspx :
...
lpPrefixString
The null-terminated prefix string. The function uses up to the
first three characters of this string as the prefix of the file name.
...

Other possible solution is to create own version of GetTempFileName()
under Windows
but i think  htta more simple and correct solution is to describe it in
docu as Windows-specific issue...

Also there are some possible problems can occur with this function
under Windows:
1. if temp directory path length more than MAXPATH-14 :
...
lpPathName
The directory path for the file name. Applications typically
specify a period (.) for the current directory or the result of the
GetTempPath function. The string cannot be longer than MAX_PATH–14
characters or GetTempFileName will fail. If this parameter is NULL, the
function fails.
...

so if templ directory will have (MAXPATHLEN-13) symbols
then PHP check of length will successfully pass
but GetTempFileName() will fail.

There is patch for fix this problem:

$ diff -upd /home/sawoy/source/php-5.2.5/main/php_open_temporary_file.c
./main/php_open_temporary_file.c
--- /home/sawoy/source/php-5.2.5/main/php_open_temporary_file.c
2007-08-10 03:13:15.0 -0700
+++ ./main/php_open_temporary_file.c2008-03-06 15:00:22.0
-0800
@@ -131,7 +131,11 @@ static int php_do_open_temporary_file(co
trailing_slash = /;
}

+#ifdef PHP_WIN32
+   if (spprintf(opened_path, 0, %s, new_state.cwd) 
(MAXPATHLEN - 14)) {
+#else
if (spprintf(opened_path, 0, %s%s%sXX, new_state.cwd,
trailing_slash, pfx) = MAXPATHLEN) {
+#endif
efree(opened_path);
free(new_state.cwd);
return -1;


2. due algo of GetTempFileName() it will be not possible to create more
than 65535 temporary files in on temp directory. 
On box where i tested it it can create only 65324 files and on next
script hangs...

Also for info: time of creation 65xxx-th file in one temp directory is
encreased in ~10-15 times :)



[2008-02-22 21:41:45] c dot d dot brengel at att dot net

Description:

It appears that when using tempnam the $prefix parameter only accepts
3 characters.  I used tempnam(getcwd(),'ADR'.date(Y.m.d).'_')
and the resulting file name ended up as ADRBA.tmp not the 
ADR2008222_BA.tmp that it should have given.

I then tried tempnam(getcwd(), 'ADR123') and stil got only ADRXX.tmp.

Not sure but would appreciate it if you could determine if this is in
fact correct behavior.



Reproduce code:
---
?php
echo getcwd() . \n\r;
chdir('tmp');
echo getcwd() . \n\r;
$file=tempnam(getcwd(),'ADR'.date(Y.m.d).'_');
echo $file;
?

Expected result:

C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADR2008222_C2.tmp 


Actual result:
--
C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADRC2.tmp 






-- 
Edit this bug report at http://bugs.php.net/?id=44222edit=1



#44222 [NEW]: tempnam $prefix parameter limitation

2008-02-22 Thread c dot d dot brengel at att dot net
From: c dot d dot brengel at att dot net
Operating system: Windows XP
PHP version:  5.2.5
PHP Bug Type: Unknown/Other Function
Bug description:  tempnam $prefix parameter limitation

Description:

It appears that when using tempnam the $prefix parameter only accepts 3
characters.  I used tempnam(getcwd(),'ADR'.date(Y.m.d).'_')
and the resulting file name ended up as ADRBA.tmp not the 
ADR2008222_BA.tmp that it should have given.

I then tried tempnam(getcwd(), 'ADR123') and stil got only ADRXX.tmp.

Not sure but would appreciate it if you could determine if this is in fact
correct behavior.



Reproduce code:
---
?php
echo getcwd() . \n\r;
chdir('tmp');
echo getcwd() . \n\r;
$file=tempnam(getcwd(),'ADR'.date(Y.m.d).'_');
echo $file;
?

Expected result:

C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADR2008222_C2.tmp 


Actual result:
--
C:\Inetpub\wwwroot\ADRAL 
C:\Inetpub\wwwroot\ADRAL\tmp 
C:\WINDOWS\Temp\ADRC2.tmp 


-- 
Edit bug report at http://bugs.php.net/?id=44222edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44222r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44222r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44222r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44222r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=44222r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=44222r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=44222r=needscript
Try newer version:http://bugs.php.net/fix.php?id=44222r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=44222r=support
Expected behavior:http://bugs.php.net/fix.php?id=44222r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=44222r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=44222r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44222r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44222r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44222r=dst
IIS Stability:http://bugs.php.net/fix.php?id=44222r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=44222r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44222r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=44222r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=44222r=mysqlcfg