]> granicus.if.org Git - php/commitdiff
MFH: Improve open_basedir checks
authorIlia Alshanetsky <iliaa@php.net>
Fri, 13 Oct 2006 01:12:11 +0000 (01:12 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 13 Oct 2006 01:12:11 +0000 (01:12 +0000)
main/php_open_temporary_file.c

index c479e9e6c69792fb250073edb3a00fb87aa82e85..a0e3f27f86f16b318433fde1e62486e670e76e4c 100644 (file)
@@ -207,7 +207,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;
-       const char *temp_dir = php_get_temporary_directory();
+       const char *temp_dir;
 
        if (!pfx) {
                pfx = "tmp.";
@@ -217,6 +217,9 @@ PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened
        }
 
        if (!dir || *dir == '\0') {
+def_tmp:
+               temp_dir = php_get_temporary_directory();
+
                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 {
@@ -228,7 +231,7 @@ PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened
        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(temp_dir, pfx, opened_path_p TSRMLS_CC);
+               goto def_tmp;
        }
        return fd;
 }