#48465 [Opn]: sys_get_temp_dir() possibly inconsistent when using TMPDIR

From: Date: Wed, 03 Jun 2009 17:53:47 +0000
Subject: #48465 [Opn]: sys_get_temp_dir() possibly inconsistent when using TMPDIR
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-138018@lists.php.net to get a copy of this message
ID: 48465 User updated by: marcel dot esser at gmail dot com Reported By: marcel dot esser at gmail dot com Status: Open Bug Type: Directory function related Operating System: Mac OS X, possibly others PHP Version: 5.2.9 New Comment: Pardon, I meant 5.2.9 CVS Also, here is diff -u output: --- main/php_open_temporary_file.c 2009-06-03 13:42:44.000000000 -0400 +++ /Users/marcelesser/php_open_temporary_file.c 2009-06-03 13:43:48.000000000 -0400 @@ -200,9 +200,16 @@ { char* s = getenv("TMPDIR"); if (s) { - temporary_directory = strdup(s); + /* on some systems (notably mac os x) TMPDIR has a DIRECTORY_SEPARATOR appended */ + if(s[strlen(s)-1] == DEFAULT_SLASH) { + temporary_directory = tsrm_strndup(s,strlen(s)-1); + } else { + temporary_directory = strdup(s); + } + return temporary_directory; } + } #ifdef P_tmpdir /* Use the standard default temporary directory. */ Previous Comments: ------------------------------------------------------------------------ [2009-06-03 17:51:17] marcel dot esser at gmail dot com Description: ------------ Some systems add a terminating directory separator to the TMPDIR env variable, such as Mac OS X. This is not consistent with the fallback default for sys_get_temp_dir(), which is '/tmp'. This causes problems when constructing filenames when not using tempnam(). Here is a short patch against 5.2 HEAD 203c203,209 < temporary_directory = strdup(s); --- > /* on some systems (notably mac os x) TMPDIR has a DIRECTORY_SEPARATOR appended */ > if(s[strlen(s)-1] == DEFAULT_SLASH) { > temporary_directory = tsrm_strndup(s,strlen(s)-1); > } else { > temporary_directory = strdup(s); > } > 205a212 > Reproduce code: --------------- <?php echo sys_get_temp_dir() . "\n"; Expected result: ---------------- /var/folders/yC/yCto0tGnHIqmgIv2v8-pEk+++TI/-Tmp- Actual result: -------------- /var/folders/yC/yCto0tGnHIqmgIv2v8-pEk+++TI/-Tmp-/ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48465&edit=1

« previous php.bugs (#138018) next »