You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The variable php_cli_server_workers_max is parsed from environment variable and thus is controlled. When setting php_cli_server_workers_max to a large value (e.g., INT64_MAX), the multiplication php_cli_server_workers_max * sizeof(pid_t) could wrap to a small value. A buffer smaller than expected will be allocated and this can lead to subsequent buffer overflow.
Notice that the C standard does not clearly states that calloc will check for multiplication overflow itself (see here). It will be better to also restrict the maximum value for php_cli_server_workers_max in the code.
PHP Version
github master
Operating System
No response
The text was updated successfully, but these errors were encountered:
I agree that this should be improved, but setting a very large number is unlikely to work anyway, or is it?
With a very large number for php_cli_server_workers_max, the actual buffer size of php_cli_server_workers is actually a small value due to the wrap-around. Then the following loop can lead to out of bound buffer access (only require fork to succeed for a small number of times):
for (php_cli_server_worker = 0;
php_cli_server_worker < php_cli_server_workers_max;
php_cli_server_worker++) {
pid_t pid = fork();
if (pid < 0) {
/* no more forks allowed, work with what we have ... */
php_cli_server_workers_max =
php_cli_server_worker + 1;
return;
} else if (pid == 0) {
return;
} else {
php_cli_server_workers[php_cli_server_worker] = pid;
}
}
Description
In the file
sapi/cli/php_cli_server.c
, the functionphp_cli_server_startup_workers
has the following code:The variable
php_cli_server_workers_max
is parsed from environment variable and thus is controlled. When settingphp_cli_server_workers_max
to a large value (e.g.,INT64_MAX
), the multiplicationphp_cli_server_workers_max * sizeof(pid_t)
could wrap to a small value. A buffer smaller than expected will be allocated and this can lead to subsequent buffer overflow.Notice that the C standard does not clearly states that
calloc
will check for multiplication overflow itself (see here). It will be better to also restrict the maximum value forphp_cli_server_workers_max
in the code.PHP Version
github master
Operating System
No response
The text was updated successfully, but these errors were encountered: