Skip to content

Commit 8bd16e2

Browse files
author
Ilia Alshanetsky
committed
Improve open_basedir checks
1 parent 33879ec commit 8bd16e2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

main/php_open_temporary_file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ PHPAPI const char* php_get_temporary_directory(void)
206206
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC)
207207
{
208208
int fd;
209-
const char *temp_dir = php_get_temporary_directory();
209+
const char *temp_dir;
210210

211211
if (!pfx) {
212212
pfx = "tmp.";
@@ -216,6 +216,9 @@ PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened
216216
}
217217

218218
if (!dir || *dir == '\0') {
219+
def_tmp:
220+
temp_dir = php_get_temporary_directory();
221+
219222
if (temp_dir && *temp_dir != '\0' && !php_check_open_basedir(temp_dir TSRMLS_CC)) {
220223
return php_do_open_temporary_file(temp_dir, pfx, opened_path_p TSRMLS_CC);
221224
} else {
@@ -227,7 +230,7 @@ PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened
227230
fd = php_do_open_temporary_file(dir, pfx, opened_path_p TSRMLS_CC);
228231
if (fd == -1) {
229232
/* Use default temporary directory. */
230-
fd = php_do_open_temporary_file(temp_dir, pfx, opened_path_p TSRMLS_CC);
233+
goto def_tmp;
231234
}
232235
return fd;
233236
}

0 commit comments

Comments
 (0)