From 12e8eef7608753c385815a01c2c088960ed8e58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Loyet?= Date: Sun, 13 Jun 2010 10:30:35 +0000 Subject: [PATCH] Fix #52067, chroot and chdir path were not checked at startup. If configured with unexistant directories, FPM entered in an error loop. --- sapi/fpm/fpm/fpm_conf.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index a9c23840f67..e2c0e30a134 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -99,6 +99,18 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = { { 0, 0, 0 } }; +static int fpm_conf_is_dir(char *path) /* {{{ */ +{ + struct stat sb; + + if (stat(path, &sb) != 0) { + return 0; + } + + return (sb.st_mode & S_IFMT) == S_IFDIR; +} +/* }}} */ + static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */ { char *val = Z_STRVAL_P(value); @@ -565,6 +577,48 @@ static int fpm_conf_process_all_pools() /* {{{ */ fpm_status_set_pm(wp->shm_status, wp->config->pm); /* memset(&fpm_status.last_update, 0, sizeof(fpm_status.last_update)); */ } + + if (wp->config->chroot && *wp->config->chroot) { + if (*wp->config->chroot != '/') { + zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chroot path '%s' must start with a '/'", wp->config->name, wp->config->chroot); + return -1; + } + if (!fpm_conf_is_dir(wp->config->chroot)) { + zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chroot path '%s' does not exist or is not a directory", wp->config->name, wp->config->chroot); + return -1; + } + } + + if (wp->config->chdir && *wp->config->chdir) { + if (*wp->config->chdir != '/') { + zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' must start with a '/'", wp->config->name, wp->config->chdir); + return -1; + } + + if (wp->config->chroot) { + char *buf; + size_t len; + + len = strlen(wp->config->chroot) + strlen(wp->config->chdir) + 1; + buf = malloc(sizeof(char) * len); + if (!buf) { + zlog(ZLOG_STUFF, ZLOG_SYSERROR, "[pool %s] malloc() failed", wp->config->name); + return -1; + } + snprintf(buf, len, "%s%s", wp->config->chroot, wp->config->chdir); + if (!fpm_conf_is_dir(buf)) { + zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' wihtin the chroot path '%s' ('%s') does not exist or is not a directory", wp->config->name, wp->config->chdir, wp->config->chroot, buf); + free(buf); + return -1; + } + free(buf); + } else { + if (!fpm_conf_is_dir(wp->config->chdir)) { + zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' does not exist or is not a directory", wp->config->name, wp->config->chdir); + return -1; + } + } + } } return 0; }