Fixed off-by-one overflow, updated test case

This commit is contained in:
Tjerk Meesters 2014-08-20 21:44:14 +08:00
parent b035466c66
commit 91ee8f491a
2 changed files with 13 additions and 9 deletions

View File

@ -4966,12 +4966,14 @@ PHP_FUNCTION(uv_exepath)
*/
PHP_FUNCTION(uv_cwd)
{
char buffer[1024] = {0};
size_t buffer_sz = sizeof(buffer);
uv_cwd(buffer, buffer_sz);
buffer[buffer_sz] = '\0';
char buffer[MAXPATHLEN];
if (zend_parse_parameters_none() == FAILURE) {
return;
}
uv_cwd(buffer, MAXPATHLEN);
RETURN_STRING(buffer, 1);
}
/* }}} */

View File

@ -2,7 +2,7 @@
Check for uv_chdir
--FILE--
<?php
@uv_chdir(); // don't SEGV
uv_chdir(); // don't SEGV
uv_chdir(dirname(__FILE__));
if (uv_cwd() == dirname(__FILE__)) {
@ -11,5 +11,7 @@ if (uv_cwd() == dirname(__FILE__)) {
echo "FAILED: expected " . dirname(__FILE__) . ", but " . uv_cwd();
}
--EXPECT--
OK
--EXPECTF--
Warning: uv_chdir() expects exactly 1 parameter, 0 given in %s on line %d
OK