Skip to content

sapi/fpm/status: replace variable-length array with emalloc() #10660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sapi/fpm/fpm/fpm_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ int fpm_status_export_to_zval(zval *status)

/* copy the scoreboard not to bother other processes */
scoreboard = *scoreboard_p;
struct fpm_scoreboard_proc_s procs[scoreboard.nprocs];
struct fpm_scoreboard_proc_s *procs = safe_emalloc(scoreboard.nprocs, sizeof(*procs), 0);
if (procs == NULL) {
return FAILURE;
Copy link
Member

@devnexen devnexen Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest not to mix "semantics", FAILURE is meant for zend_result type, like above, I would suggest to return just -1.

Copy link
Contributor Author

@MaxKellermann MaxKellermann Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I have assumed here is that fpm_status_export_to_zval() is really supposed to return zend_result according to PHP's guidelines, but I have not yet submitted a PR that actually does this.
(It already returns the hard-coded integers, but not formally zend_result, but that's just a formal change.)

}

struct fpm_scoreboard_proc_s *proc_p;
for(i=0; i<scoreboard.nprocs; i++) {
Expand Down Expand Up @@ -129,6 +132,7 @@ int fpm_status_export_to_zval(zval *status)
add_assoc_long(&fpm_proc_stat, "last-request-memory", procs[i].request_stage == FPM_REQUEST_ACCEPTING ? procs[i].memory : 0);
add_next_index_zval(&fpm_proc_stats, &fpm_proc_stat);
}
efree(procs);
add_assoc_zval(status, "procs", &fpm_proc_stats);
return 0;
}
Expand Down