svn: /php/php-src/ branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c trunk/sapi/fpm/fpm/fpm_conf.c
| From: | Jérôme Loyet | Date: | Sun, 13 Jun 2010 10:30:35 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c trunk/sapi/fpm/fpm/fpm_conf.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-62877@lists.php.net to get a copy of this message | ||
fat Sun, 13 Jun 2010 10:30:35 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=300418
Log:
Fix #52067, chroot and chdir path were not checked at startup. If configured with unexistant
directories, FPM entered in an error loop.
Bug: http://bugs.php.net/52067 (Assigned) chdir to a
nonexisting directory when chrooting is buggy
Changed paths:
U php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c
U php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
Modified: php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c 2010-06-13 07:55:10 UTC (rev 300417)
+++ php/php-src/branches/PHP_5_3/sapi/fpm/fpm/fpm_conf.c 2010-06-13 10:30:35 UTC (rev 300418)
@@ -99,6 +99,18 @@
{ 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 @@
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;
}
Modified: php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c
===================================================================
--- php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c 2010-06-13 07:55:10 UTC (rev 300417)
+++ php/php-src/trunk/sapi/fpm/fpm/fpm_conf.c 2010-06-13 10:30:35 UTC (rev 300418)
@@ -99,6 +99,18 @@
{ 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 @@
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;
}