Skip to content

Commit 4ca3df5

Browse files
author
Ilia Alshanetsky
committed
Check 2nd parameter of tempnam() against path components.
1 parent a93bd9d commit 4ca3df5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? Mar 2006, PHP 5.1.3RC2
4+
- Check 2nd parameter of tempnam() against path components. (Ilia)
45
- Fixed Apache2 SAPIs header handler modifying header strings. (Mike)
56
- Allowed 'auto_globals_jit' work together with 'register_argc_argv'. (Dmitry)
67
- Eliminated run-time constant fetching for TRUE, FALSE and NULL. (Dmitry)

ext/standard/file.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,9 @@ PHP_FUNCTION(tempnam)
773773
zval **arg1, **arg2;
774774
char *d;
775775
char *opened_path;
776-
char p[64];
776+
char *p;
777777
int fd;
778+
size_t p_len;
778779

779780
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
780781
WRONG_PARAM_COUNT;
@@ -787,14 +788,19 @@ PHP_FUNCTION(tempnam)
787788
}
788789

789790
d = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
790-
strlcpy(p, Z_STRVAL_PP(arg2), sizeof(p));
791+
792+
php_basename(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2), NULL, 0, &p, &p_len TSRMLS_CC);
793+
if (p_len > 64) {
794+
p[63] = '\0';
795+
}
791796

792797
if ((fd = php_open_temporary_fd(d, p, &opened_path TSRMLS_CC)) >= 0) {
793798
close(fd);
794799
RETVAL_STRING(opened_path, 0);
795800
} else {
796801
RETVAL_FALSE;
797802
}
803+
efree(p);
798804
efree(d);
799805
}
800806
/* }}} */

0 commit comments

Comments
 (0)