Commit 5850c7de7c5 for php.net
commit 5850c7de7c5032a84edbde17360de3ddc00fce57
Author: Max Kellermann <max.kellermann@ionos.com>
Date: Tue Feb 21 16:50:31 2023 +0100
sapi/fpm: remove use of variable-length arrays (#10645)
According to @cmb69, PHP does not require VLA support
(https://github.com/php/php-src/pull/10304#discussion_r1069343092).
VLAs are a bad idea for several reasons, so let's get rid of them.
Two of the VLAs were probably unintended; unlike C++, C doesn't have
the concept of "constant expressions", so an array with a "const"
length is technically still a VLA. This is fixed by removing the
"const" variable, and using sizeof() instead.
(cherry picked from commit ff2a211d55650201e5bbe370c319a0c913613eb9)
diff --git a/sapi/fpm/fpm/fpm_php_trace.c b/sapi/fpm/fpm/fpm_php_trace.c
index 0e1d8e3f6ce..b1535b26e3e 100644
--- a/sapi/fpm/fpm/fpm_php_trace.c
+++ b/sapi/fpm/fpm/fpm_php_trace.c
@@ -39,15 +39,14 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
int callers_limit = child->wp->config->request_slowlog_trace_depth;
pid_t pid = child->pid;
struct timeval tv;
- static const int buf_size = 1024;
- char buf[buf_size];
+ char buf[1024];
long execute_data;
long path_translated;
long l;
gettimeofday(&tv, 0);
- zlog_print_time(&tv, buf, buf_size);
+ zlog_print_time(&tv, buf, sizeof(buf));
fprintf(slowlog, "\n%s [pool %s] pid %d\n", buf, child->wp->config->name, (int) pid);
@@ -57,7 +56,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
path_translated = l;
- if (0 > fpm_trace_get_strz(buf, buf_size, path_translated)) {
+ if (0 > fpm_trace_get_strz(buf, sizeof(buf), path_translated)) {
return -1;
}
@@ -103,7 +102,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
ZEND_UNREACHABLE();
}
} else {
- if (0 > fpm_trace_get_strz(buf, buf_size, function_name + offsetof(zend_string, val))) {
+ if (0 > fpm_trace_get_strz(buf, sizeof(buf), function_name + offsetof(zend_string, val))) {
return -1;
}
@@ -149,7 +148,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ *
file_name = l;
- if (0 > fpm_trace_get_strz(buf, buf_size, file_name + offsetof(zend_string, val))) {
+ if (0 > fpm_trace_get_strz(buf, sizeof(buf), file_name + offsetof(zend_string, val))) {
return -1;
}
diff --git a/sapi/fpm/fpm/fpm_stdio.c b/sapi/fpm/fpm/fpm_stdio.c
index dec540d17ac..c104ff987f0 100644
--- a/sapi/fpm/fpm/fpm_stdio.c
+++ b/sapi/fpm/fpm/fpm_stdio.c
@@ -168,9 +168,8 @@ int fpm_stdio_flush_child(void)
static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg) /* {{{ */
{
- static const int max_buf_size = 1024;
int fd = ev->fd;
- char buf[max_buf_size];
+ char buf[1024];
struct fpm_child_s *child;
int is_stdout;
struct fpm_event_s *event;
@@ -216,7 +215,7 @@ static void fpm_stdio_child_said(struct fpm_event_s *ev, short which, void *arg)
while (1) {
stdio_read:
- in_buf = read(fd, buf, max_buf_size - 1);
+ in_buf = read(fd, buf, sizeof(buf) - 1);
if (in_buf <= 0) { /* no data */
if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) {
/* pipe is closed or error */