]> granicus.if.org Git - php/commitdiff
Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 27 Sep 2006 23:44:13 +0000 (23:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 27 Sep 2006 23:44:13 +0000 (23:44 +0000)
NEWS
main/php_open_temporary_file.c

diff --git a/NEWS b/NEWS
index dc37153b440582901fc4cdb3dc79ea11547119da..9bb0d07074d501a44417edbfa9a7810f50a8d531 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
   (Dmitry)
 - Fixed bug #38961 (metaphone() results in segmentation fault on NetBSD). 
   (Tony)
+- Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()). (Ilia)
 - Fixed bug #38949 (Cannot get xmlns value attribute). (Rob)
 - Fixed bug #38942 (Double old-style-ctor inheritance). (Dmitry)
 - Fixed bug #38941 (imap extension does not compile against new version of
index b2e27e2f79ed8d1f2bec391f0b40732b4f6810d4..60526fa0e496999513e93611407a5128259d974d 100644 (file)
@@ -206,6 +206,7 @@ PHPAPI const char* php_get_temporary_directory(void)
 PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC)
 {
        int fd;
+       char *temp_dir = php_get_temporary_directory();
 
        if (!pfx) {
                pfx = "tmp.";
@@ -214,11 +215,19 @@ PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened
                *opened_path_p = NULL;
        }
 
+       if (!dir || *dir == '\0') {
+               if (temp_dir && *temp_dir != '\0' && !php_check_open_basedir(temp_dir TSRMLS_CC)) {
+                       return php_do_open_temporary_file(temp_dir, pfx, opened_path_p TSRMLS_CC);
+               } else {
+                       return -1;
+               }
+       }
+
        /* Try the directory given as parameter. */
        fd = php_do_open_temporary_file(dir, pfx, opened_path_p TSRMLS_CC);
        if (fd == -1) {
                /* Use default temporary directory. */
-               fd = php_do_open_temporary_file(php_get_temporary_directory(), pfx, opened_path_p TSRMLS_CC);
+               fd = php_do_open_temporary_file(temp_dir, pfx, opened_path_p TSRMLS_CC);
        }
        return fd;
 }