summaryrefslogtreecommitdiff
path: root/main/php_open_temporary_file.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-09-27 23:44:13 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-09-27 23:44:13 +0000
commit5860f471222a71e6283d23dbe4d736a27106e9a9 (patch)
treee83fb7d6c16790be572e41f497b53bbcb14c8170 /main/php_open_temporary_file.c
parent47600225e11f919470e278a2043072c985e647ba (diff)
downloadphp-git-5860f471222a71e6283d23dbe4d736a27106e9a9.tar.gz
Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()).
Diffstat (limited to 'main/php_open_temporary_file.c')
-rw-r--r--main/php_open_temporary_file.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index b2e27e2f79..60526fa0e4 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -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;
}