Skip to content

Commit ae2c5ee

Browse files
author
Ilia Alshanetsky
committed
MFB: Fixed bug #48465 (sys_get_temp_dir() possibly inconsistent when using TMPDIR).
1 parent 0e294f2 commit ae2c5ee

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

main/php_open_temporary_file.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,15 @@ PHPAPI const char* php_get_temporary_directory(void)
199199
/* On Unix use the (usual) TMPDIR environment variable. */
200200
{
201201
char* s = getenv("TMPDIR");
202-
if (s) {
203-
temporary_directory = strdup(s);
202+
if (s && *s) {
203+
int len = strlen(s);
204+
205+
if (s[len - 1] == DEFAULT_SLASH) {
206+
temporary_directory = zend_strndup(s, len - 1);
207+
} else {
208+
temporary_directory = zend_strndup(s, len);
209+
}
210+
204211
return temporary_directory;
205212
}
206213
}

0 commit comments

Comments
 (0)