Skip to content

Commit 91ee8f4

Browse files
committed
Fixed off-by-one overflow, updated test case
1 parent b035466 commit 91ee8f4

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

php_uv.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4966,12 +4966,14 @@ PHP_FUNCTION(uv_exepath)
49664966
*/
49674967
PHP_FUNCTION(uv_cwd)
49684968
{
4969-
char buffer[1024] = {0};
4970-
size_t buffer_sz = sizeof(buffer);
4971-
4972-
uv_cwd(buffer, buffer_sz);
4973-
buffer[buffer_sz] = '\0';
4974-
4969+
char buffer[MAXPATHLEN];
4970+
4971+
if (zend_parse_parameters_none() == FAILURE) {
4972+
return;
4973+
}
4974+
4975+
uv_cwd(buffer, MAXPATHLEN);
4976+
49754977
RETURN_STRING(buffer, 1);
49764978
}
49774979
/* }}} */

tests/999-uv_chdir.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Check for uv_chdir
33
--FILE--
44
<?php
5-
@uv_chdir(); // don't SEGV
5+
uv_chdir(); // don't SEGV
66

77
uv_chdir(dirname(__FILE__));
88
if (uv_cwd() == dirname(__FILE__)) {
@@ -11,5 +11,7 @@ if (uv_cwd() == dirname(__FILE__)) {
1111
echo "FAILED: expected " . dirname(__FILE__) . ", but " . uv_cwd();
1212
}
1313

14-
--EXPECT--
15-
OK
14+
--EXPECTF--
15+
16+
Warning: uv_chdir() expects exactly 1 parameter, 0 given in %s on line %d
17+
OK

0 commit comments

Comments
 (0)