8484 * SUCH DAMAGE.
8585 */
8686
87- static int php_do_open_temporary_file (const char * path , const char * pfx , zend_string * * opened_path_p )
87+ static int php_do_open_temporary_file (const char * path , const char * pfx , const char * sfx , zend_string * * opened_path_p )
8888{
8989#ifdef PHP_WIN32
9090 char * opened_path = NULL ;
@@ -97,7 +97,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
9797 char cwd [MAXPATHLEN ];
9898 cwd_state new_state ;
9999 int fd = -1 ;
100- #ifndef HAVE_MKSTEMP
100+ #ifndef HAVE_MKSTEMPS
101101 int open_flags = O_CREAT | O_TRUNC | O_RDWR
102102#ifdef PHP_WIN32
103103 | _O_BINARY
@@ -135,7 +135,7 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
135135 trailing_slash = "/" ;
136136 }
137137
138- if (snprintf (opened_path , MAXPATHLEN , "%s%s%sXXXXXX" , new_state .cwd , trailing_slash , pfx ) >= MAXPATHLEN ) {
138+ if (snprintf (opened_path , MAXPATHLEN , "%s%s%sXXXXXX%s " , new_state .cwd , trailing_slash , pfx , sfx ) >= MAXPATHLEN ) {
139139 efree (new_state .cwd );
140140 return -1 ;
141141 }
@@ -175,8 +175,8 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, zend_st
175175
176176 free (cwdw );
177177 free (pfxw );
178- #elif defined(HAVE_MKSTEMP )
179- fd = mkstemp (opened_path );
178+ #elif defined(HAVE_MKSTEMPS )
179+ fd = mkstemps (opened_path , strlen ( sfx ) );
180180#else
181181 if (mktemp (opened_path )) {
182182 fd = VCWD_OPEN (opened_path , open_flags );
@@ -283,14 +283,17 @@ PHPAPI const char* php_get_temporary_directory(void)
283283 * This function should do its best to return a file pointer to a newly created
284284 * unique file, on every platform.
285285 */
286- PHPAPI int php_open_temporary_fd_ex (const char * dir , const char * pfx , zend_string * * opened_path_p , uint32_t flags )
286+ PHPAPI int php_open_temporary_fd_ex2 (const char * dir , const char * pfx , const char * sfx , zend_string * * opened_path_p , uint32_t flags )
287287{
288288 int fd ;
289289 const char * temp_dir ;
290290
291291 if (!pfx ) {
292292 pfx = "tmp." ;
293293 }
294+ if (!sfx ) {
295+ sfx = "" ;
296+ }
294297 if (opened_path_p ) {
295298 * opened_path_p = NULL ;
296299 }
@@ -302,7 +305,7 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
302305 if (temp_dir &&
303306 * temp_dir != '\0' &&
304307 (!(flags & PHP_TMP_FILE_OPEN_BASEDIR_CHECK_ON_FALLBACK ) || !php_check_open_basedir (temp_dir ))) {
305- return php_do_open_temporary_file (temp_dir , pfx , opened_path_p );
308+ return php_do_open_temporary_file (temp_dir , pfx , sfx , opened_path_p );
306309 } else {
307310 return -1 ;
308311 }
@@ -313,7 +316,7 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
313316 }
314317
315318 /* Try the directory given as parameter. */
316- fd = php_do_open_temporary_file (dir , pfx , opened_path_p );
319+ fd = php_do_open_temporary_file (dir , pfx , sfx , opened_path_p );
317320 if (fd == -1 ) {
318321 /* Use default temporary directory. */
319322 if (!(flags & PHP_TMP_FILE_SILENT )) {
@@ -324,6 +327,11 @@ PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_strin
324327 return fd ;
325328}
326329
330+ PHPAPI int php_open_temporary_fd_ex (const char * dir , const char * pfx , zend_string * * opened_path_p , uint32_t flags )
331+ {
332+ return php_open_temporary_fd_ex2 (dir , pfx , NULL , opened_path_p , flags );
333+ }
334+
327335PHPAPI int php_open_temporary_fd (const char * dir , const char * pfx , zend_string * * opened_path_p )
328336{
329337 return php_open_temporary_fd_ex (dir , pfx , opened_path_p , PHP_TMP_FILE_DEFAULT );
0 commit comments