]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #48465 (sys_get_temp_dir() possibly inconsistent when using
authorIlia Alshanetsky <iliaa@php.net>
Tue, 30 Jun 2009 12:20:35 +0000 (12:20 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 30 Jun 2009 12:20:35 +0000 (12:20 +0000)
TMPDIR).

main/php_open_temporary_file.c

index ee7f0df75f3668db954a405c00a2bafed4b18cb0..7c90f1f39b71c27b506322c61d210b5e5fe2b32f 100644 (file)
@@ -199,8 +199,15 @@ PHPAPI const char* php_get_temporary_directory(void)
        /* On Unix use the (usual) TMPDIR environment variable. */
        {
                char* s = getenv("TMPDIR");
-               if (s) {
-                       temporary_directory = strdup(s);
+               if (s && *s) {
+                       int len = strlen(s);
+
+                       if (s[len - 1] == DEFAULT_SLASH) {
+                               temporary_directory = zend_strndup(s, len - 1);
+                       } else {
+                               temporary_directory = zend_strndup(s, len);
+                       }
+
                        return temporary_directory;
                }
        }