From: Ilia Alshanetsky Date: Wed, 27 Sep 2006 23:45:36 +0000 (+0000) Subject: MFH: Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()). X-Git-Tag: php-4.4.5RC1~64 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d39cfd613119589d094b0c14fa19145387c5840;p=php MFH: Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()). --- diff --git a/NEWS b/NEWS index 2eb6dd2dac..1559b2037f 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ PHP 4 NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2006, Version 4.4.5 - Updated PCRE to version 6.7. (Ilia) +- Fixed bug #38963 (Fixed a possible open_basedir bypass in tempnam()). (Ilia) - Fixed bug #38534 (segfault when calling setlocale() in userspace session handler). (Tony) - Fixed bug #38450 (constructor is not called for classes used in userspace diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c index e870db76f1..e4ce52910e 100644 --- a/main/php_open_temporary_file.c +++ b/main/php_open_temporary_file.c @@ -207,6 +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; + char *temp_dir = php_get_temporary_directory(); if (!pfx) { pfx = "tmp."; @@ -215,11 +216,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; }