summaryrefslogtreecommitdiff
path: root/sapi/fpm
diff options
context:
space:
mode:
authorJulien Pauli <jpauli@php.net>2016-09-23 13:24:31 +0200
committerJulien Pauli <jpauli@php.net>2016-09-23 13:52:58 +0200
commita22175b06f22965e0d79e2b5bb6c734950adfc5d (patch)
tree0f237071efc8247277ef0a13b19e1feb66817394 /sapi/fpm
parent807004a446c3e19bd1d12111cda841fea3db4135 (diff)
downloadphp-git-a22175b06f22965e0d79e2b5bb6c734950adfc5d.tar.gz
Formatting. Fix possible memory corruption in FPM SHM management
Diffstat (limited to 'sapi/fpm')
-rw-r--r--sapi/fpm/fpm/fpm_scoreboard.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/sapi/fpm/fpm/fpm_scoreboard.c b/sapi/fpm/fpm/fpm_scoreboard.c
index 3e57333e9f..e1e69c9780 100644
--- a/sapi/fpm/fpm/fpm_scoreboard.c
+++ b/sapi/fpm/fpm/fpm_scoreboard.c
@@ -25,7 +25,7 @@ static float fpm_scoreboard_tick;
int fpm_scoreboard_init_main() /* {{{ */
{
struct fpm_worker_pool_s *wp;
- int i;
+ unsigned int i;
#ifdef HAVE_TIMES
#if (defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK))
@@ -42,6 +42,9 @@ int fpm_scoreboard_init_main() /* {{{ */
for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
+ size_t scoreboard_size, scoreboard_nprocs_size;
+ void *shm_mem;
+
if (wp->config->pm_max_children < 1) {
zlog(ZLOG_ERROR, "[pool %s] Unable to create scoreboard SHM because max_client is not set", wp->config->name);
return -1;
@@ -52,21 +55,22 @@ int fpm_scoreboard_init_main() /* {{{ */
return -1;
}
- int scoreboard_size = sizeof(struct fpm_scoreboard_s) + (wp->config->pm_max_children) * sizeof(struct fpm_scoreboard_proc_s *);
- int scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * wp->config->pm_max_children;
- void *shm_mem = fpm_shm_alloc(scoreboard_size + scoreboard_nprocs_size);
+ scoreboard_size = sizeof(struct fpm_scoreboard_s) + (wp->config->pm_max_children) * sizeof(struct fpm_scoreboard_proc_s *);
+ scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * wp->config->pm_max_children;
+ shm_mem = fpm_shm_alloc(scoreboard_size + scoreboard_nprocs_size);
+
if (!shm_mem) {
return -1;
}
- wp->scoreboard = shm_mem;
+ wp->scoreboard = shm_mem;
wp->scoreboard->nprocs = wp->config->pm_max_children;
- shm_mem += scoreboard_size;
- for (i = 0; i < wp->scoreboard->nprocs; i++) {
+ shm_mem += scoreboard_size;
+
+ for (i = 0; i < wp->scoreboard->nprocs; i++, shm_mem += sizeof(struct fpm_scoreboard_proc_s)) {
wp->scoreboard->procs[i] = shm_mem;
- shm_mem += sizeof(struct fpm_scoreboard_proc_s);
}
- wp->scoreboard->pm = wp->config->pm;
+ wp->scoreboard->pm = wp->config->pm;
wp->scoreboard->start_epoch = time(NULL);
strlcpy(wp->scoreboard->pool, wp->config->name, sizeof(wp->scoreboard->pool));
}
@@ -234,15 +238,15 @@ void fpm_scoreboard_proc_release(struct fpm_scoreboard_proc_s *proc) /* {{{ */
void fpm_scoreboard_free(struct fpm_scoreboard_s *scoreboard) /* {{{ */
{
- int i;
+ size_t scoreboard_size, scoreboard_nprocs_size;
if (!scoreboard) {
zlog(ZLOG_ERROR, "**scoreboard is NULL");
return;
}
- int scoreboard_size = sizeof(struct fpm_scoreboard_s) + (scoreboard->nprocs) * sizeof(struct fpm_scoreboard_proc_s *);
- int scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * scoreboard->nprocs;
+ scoreboard_size = sizeof(struct fpm_scoreboard_s) + (scoreboard->nprocs) * sizeof(struct fpm_scoreboard_proc_s *);
+ scoreboard_nprocs_size = sizeof(struct fpm_scoreboard_proc_s) * scoreboard->nprocs;
fpm_shm_free(scoreboard, scoreboard_size + scoreboard_nprocs_size);
}