From: Ilia Alshanetsky Date: Mon, 27 Mar 2006 23:41:05 +0000 (+0000) Subject: MFB51: Check 2nd parameter of tempnam() against path components. X-Git-Tag: RELEASE_1_3~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75c7f810eac6a60243becb7b6398b3c8d6579973;p=php MFB51: Check 2nd parameter of tempnam() against path components. --- diff --git a/ext/standard/file.c b/ext/standard/file.c index dc069ff6ee..042e9caf83 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -800,8 +800,9 @@ PHP_FUNCTION(tempnam) zval **arg1, **arg2; char *d; char *opened_path; - char p[64]; + char *p; int fd; + size_t p_len; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -814,7 +815,11 @@ PHP_FUNCTION(tempnam) } d = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1)); - strlcpy(p, Z_STRVAL_PP(arg2), sizeof(p)); + + php_basename(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2), NULL, 0, &p, &p_len TSRMLS_CC); + if (p_len > 64) { + p[63] = '\0'; + } if ((fd = php_open_temporary_fd(d, p, &opened_path TSRMLS_CC)) >= 0) { close(fd); @@ -825,6 +830,7 @@ PHP_FUNCTION(tempnam) } else { RETVAL_FALSE; } + efree(p); efree(d); } /* }}} */