diff options
author | Ondřej Surý <ondrej@sury.org> | 2013-05-09 17:32:08 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2013-05-09 17:32:08 +0200 |
commit | d674441ee1b9e7407f464b2692d9f5a0e2be3b4e (patch) | |
tree | cc4885524786f143bcc1af7d6c3f86fb571905de /sapi | |
parent | 367111123281ebfd2876d4c8cf33414b394f489a (diff) | |
download | php-d674441ee1b9e7407f464b2692d9f5a0e2be3b4e.tar.gz |
Imported Upstream version 5.5.0~rc1upstream/5.5.0_rc1
Diffstat (limited to 'sapi')
-rw-r--r-- | sapi/fpm/fpm/fpm_conf.c | 17 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_log.c | 16 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_main.c | 215 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_signals.c | 4 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_sockets.c | 10 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_stdio.c | 5 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_worker_pool.c | 20 | ||||
-rw-r--r-- | sapi/fpm/fpm/fpm_worker_pool.h | 1 |
8 files changed, 166 insertions, 122 deletions
diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 25e2cc43a..0a8a0e37e 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -540,12 +540,17 @@ static char *fpm_conf_set_array(zval *key, zval *value, void **config, int conve kv->key = strdup(Z_STRVAL_P(key)); if (!kv->key) { + free(kv); return "fpm_conf_set_array: strdup(key) failed"; } if (convert_to_bool) { char *err = fpm_conf_set_boolean(value, &subconf, 0); - if (err) return err; + if (err) { + free(kv->key); + free(kv); + return err; + } kv->value = strdup(b ? "1" : "0"); } else { kv->value = strdup(Z_STRVAL_P(value)); @@ -556,6 +561,7 @@ static char *fpm_conf_set_array(zval *key, zval *value, void **config, int conve if (!kv->value) { free(kv->key); + free(kv); return "fpm_conf_set_array: strdup(value) failed"; } @@ -578,6 +584,7 @@ static void *fpm_worker_pool_config_alloc() /* {{{ */ wp->config = malloc(sizeof(struct fpm_worker_pool_config_s)); if (!wp->config) { + fpm_worker_pool_free(wp); return 0; } @@ -1002,7 +1009,7 @@ static int fpm_conf_process_all_pools() /* {{{ */ nb_ext = 0; /* find the number of extensions */ - while ((ext = strtok(limit_extensions, " \t"))) { + while (strtok(limit_extensions, " \t")) { limit_extensions = NULL; nb_ext++; } @@ -1024,8 +1031,8 @@ static int fpm_conf_process_all_pools() /* {{{ */ nb_ext = 0; /* parse the string and save the extension in the array */ - while ((ext = strtok(security_limit_extensions, " \t"))) { - security_limit_extensions = NULL; + while ((ext = strtok(limit_extensions, " \t"))) { + limit_extensions = NULL; wp->limit_extensions[nb_ext++] = strdup(ext); } @@ -1107,6 +1114,7 @@ int fpm_conf_write_pid() /* {{{ */ if (len != write(fd, buf, len)) { zlog(ZLOG_SYSERROR, "Unable to write to the PID file."); + close(fd); return -1; } close(fd); @@ -1460,6 +1468,7 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ if (ini_recursion++ > 4) { zlog(ZLOG_ERROR, "failed to include more than 5 files recusively"); + close(fd); return -1; } diff --git a/sapi/fpm/fpm/fpm_log.c b/sapi/fpm/fpm/fpm_log.c index 6b014b500..4e1a057db 100644 --- a/sapi/fpm/fpm/fpm_log.c +++ b/sapi/fpm/fpm/fpm_log.c @@ -57,7 +57,9 @@ int fpm_log_open(int reopen) /* {{{ */ wp->log_fd = fd; } - fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); + if (0 > fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)) { + zlog(ZLOG_WARNING, "failed to change attribute of access_log"); + } } return ret; @@ -237,7 +239,7 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ case 'f': /* script */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.script_filename && *proc.script_filename ? proc.script_filename : "-"); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", *proc.script_filename ? proc.script_filename : "-"); } break; @@ -249,7 +251,7 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ case 'm': /* method */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.request_method && *proc.request_method ? proc.request_method : "-"); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", *proc.request_method ? proc.request_method : "-"); } break; @@ -347,19 +349,19 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ case 'q': /* query_string */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.query_string ? proc.query_string : ""); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.query_string); } break; case 'Q': /* '?' */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.query_string && *proc.query_string ? "?" : ""); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", *proc.query_string ? "?" : ""); } break; case 'r': /* request URI */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.request_uri ? proc.request_uri : "-"); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.request_uri); } break; @@ -397,7 +399,7 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */ case 'u': /* remote user */ if (!test) { - len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.auth_user ? proc.auth_user : "-"); + len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", proc.auth_user); } break; diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 61088c465..043e0e00a 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1098,7 +1098,7 @@ static void init_request_info(TSRMLS_D) #define APACHE_PROXY_FCGI_PREFIX "proxy:fcgi://" /* Fix proxy URLs in SCRIPT_FILENAME generated by Apache mod_proxy_fcgi: - * proxy:fcgi://localhost:9000/some-dir/info.php/test + * proxy:fcgi://localhost:9000/some-dir/info.php/test?foo=bar * should be changed to: * /some-dir/info.php/test * See: http://bugs.php.net/bug.php?id=54152 @@ -1118,6 +1118,11 @@ static void init_request_info(TSRMLS_D) memmove(env_script_filename, p, strlen(p) + 1); apache_was_here = 1; } + /* ignore query string if sent by Apache (RewriteRule) */ + p = strchr(env_script_filename, '?'); + if (p) { + *p =0; + } } if (CGIG(fix_pathinfo)) { @@ -1173,119 +1178,123 @@ static void init_request_info(TSRMLS_D) int len = script_path_translated_len; char *ptr; - while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) { - *ptr = 0; - if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { - /* - * okay, we found the base script! - * work out how many chars we had to strip off; - * then we can modify PATH_INFO - * accordingly - * - * we now have the makings of - * PATH_INFO=/test - * SCRIPT_FILENAME=/docroot/info.php - * - * we now need to figure out what docroot is. - * if DOCUMENT_ROOT is set, this is easy, otherwise, - * we have to play the game of hide and seek to figure - * out what SCRIPT_NAME should be - */ - int ptlen = strlen(pt); - int slen = len - ptlen; - int pilen = env_path_info ? strlen(env_path_info) : 0; - int tflag = 0; - char *path_info; - if (apache_was_here) { - /* recall that PATH_INFO won't exist */ - path_info = script_path_translated + ptlen; - tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0)); - } else { - path_info = env_path_info ? env_path_info + pilen - slen : NULL; - tflag = (orig_path_info != path_info); - } + if (pt) { + while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) { + *ptr = 0; + if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) { + /* + * okay, we found the base script! + * work out how many chars we had to strip off; + * then we can modify PATH_INFO + * accordingly + * + * we now have the makings of + * PATH_INFO=/test + * SCRIPT_FILENAME=/docroot/info.php + * + * we now need to figure out what docroot is. + * if DOCUMENT_ROOT is set, this is easy, otherwise, + * we have to play the game of hide and seek to figure + * out what SCRIPT_NAME should be + */ + int ptlen = strlen(pt); + int slen = len - ptlen; + int pilen = env_path_info ? strlen(env_path_info) : 0; + int tflag = 0; + char *path_info; + if (apache_was_here) { + /* recall that PATH_INFO won't exist */ + path_info = script_path_translated + ptlen; + tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0)); + } else { + path_info = env_path_info ? env_path_info + pilen - slen : NULL; + tflag = (orig_path_info != path_info); + } - if (tflag) { - if (orig_path_info) { - char old; - - _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); - old = path_info[0]; - path_info[0] = 0; - if (!orig_script_name || - strcmp(orig_script_name, env_path_info) != 0) { - if (orig_script_name) { - _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + if (tflag) { + if (orig_path_info) { + char old; + + _sapi_cgibin_putenv("ORIG_PATH_INFO", orig_path_info TSRMLS_CC); + old = path_info[0]; + path_info[0] = 0; + if (!orig_script_name || + strcmp(orig_script_name, env_path_info) != 0) { + if (orig_script_name) { + _sapi_cgibin_putenv("ORIG_SCRIPT_NAME", orig_script_name TSRMLS_CC); + } + SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_path_info TSRMLS_CC); + } else { + SG(request_info).request_uri = orig_script_name; } - SG(request_info).request_uri = _sapi_cgibin_putenv("SCRIPT_NAME", env_path_info TSRMLS_CC); - } else { - SG(request_info).request_uri = orig_script_name; + path_info[0] = old; } - path_info[0] = old; + env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); } - env_path_info = _sapi_cgibin_putenv("PATH_INFO", path_info TSRMLS_CC); - } - if (!orig_script_filename || - strcmp(orig_script_filename, pt) != 0) { - if (orig_script_filename) { - _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); - } - script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); - } - TRANSLATE_SLASHES(pt); - - /* figure out docroot - * SCRIPT_FILENAME minus SCRIPT_NAME - */ - if (env_document_root) { - int l = strlen(env_document_root); - int path_translated_len = 0; - char *path_translated = NULL; - - if (l && env_document_root[l - 1] == '/') { - --l; + if (!orig_script_filename || + strcmp(orig_script_filename, pt) != 0) { + if (orig_script_filename) { + _sapi_cgibin_putenv("ORIG_SCRIPT_FILENAME", orig_script_filename TSRMLS_CC); + } + script_path_translated = _sapi_cgibin_putenv("SCRIPT_FILENAME", pt TSRMLS_CC); } + TRANSLATE_SLASHES(pt); - /* we have docroot, so we should have: - * DOCUMENT_ROOT=/docroot - * SCRIPT_FILENAME=/docroot/info.php + /* figure out docroot + * SCRIPT_FILENAME minus SCRIPT_NAME */ + if (env_document_root) { + int l = strlen(env_document_root); + int path_translated_len = 0; + char *path_translated = NULL; - /* PATH_TRANSLATED = DOCUMENT_ROOT + PATH_INFO */ - path_translated_len = l + (env_path_info ? strlen(env_path_info) : 0); - path_translated = (char *) emalloc(path_translated_len + 1); - memcpy(path_translated, env_document_root, l); - if (env_path_info) { - memcpy(path_translated + l, env_path_info, (path_translated_len - l)); - } - path_translated[path_translated_len] = '\0'; - if (orig_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); - } - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); - efree(path_translated); - } else if ( env_script_name && - strstr(pt, env_script_name) - ) { - /* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */ - int ptlen = strlen(pt) - strlen(env_script_name); - int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0); - char *path_translated = NULL; - - path_translated = (char *) emalloc(path_translated_len + 1); - memcpy(path_translated, pt, ptlen); - if (env_path_info) { - memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen); - } - path_translated[path_translated_len] = '\0'; - if (orig_path_translated) { - _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + if (l && env_document_root[l - 1] == '/') { + --l; + } + + /* we have docroot, so we should have: + * DOCUMENT_ROOT=/docroot + * SCRIPT_FILENAME=/docroot/info.php + */ + + /* PATH_TRANSLATED = DOCUMENT_ROOT + PATH_INFO */ + path_translated_len = l + (env_path_info ? strlen(env_path_info) : 0); + path_translated = (char *) emalloc(path_translated_len + 1); + memcpy(path_translated, env_document_root, l); + if (env_path_info) { + memcpy(path_translated + l, env_path_info, (path_translated_len - l)); + } + path_translated[path_translated_len] = '\0'; + if (orig_path_translated) { + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + } + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); + efree(path_translated); + } else if ( env_script_name && + strstr(pt, env_script_name) + ) { + /* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */ + int ptlen = strlen(pt) - strlen(env_script_name); + int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0); + char *path_translated = NULL; + + path_translated = (char *) emalloc(path_translated_len + 1); + memcpy(path_translated, pt, ptlen); + if (env_path_info) { + memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen); + } + path_translated[path_translated_len] = '\0'; + if (orig_path_translated) { + _sapi_cgibin_putenv("ORIG_PATH_TRANSLATED", orig_path_translated TSRMLS_CC); + } + env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); + efree(path_translated); } - env_path_translated = _sapi_cgibin_putenv("PATH_TRANSLATED", path_translated TSRMLS_CC); - efree(path_translated); + break; } - break; } + } else { + ptr = NULL; } if (!ptr) { /* diff --git a/sapi/fpm/fpm/fpm_signals.c b/sapi/fpm/fpm/fpm_signals.c index 8993a860a..c5d0692f1 100644 --- a/sapi/fpm/fpm/fpm_signals.c +++ b/sapi/fpm/fpm/fpm_signals.c @@ -145,7 +145,9 @@ static void sig_soft_quit(int signo) /* {{{ */ /* closing fastcgi listening socket will force fcgi_accept() exit immediately */ close(0); - socket(AF_UNIX, SOCK_STREAM, 0); + if (0 > socket(AF_UNIX, SOCK_STREAM, 0)) { + zlog(ZLOG_WARNING, "failed to create a new socket"); + } fpm_php_soft_quit(); errno = saved_errno; } diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index 76759e7f2..f959cf36d 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -167,7 +167,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct { int flags = 1; int sock; - mode_t saved_umask; + mode_t saved_umask = 0; sock = socket(sa->sa_family, SOCK_STREAM, 0); @@ -176,11 +176,14 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct return -1; } - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags)); + if (0 > setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags))) { + zlog(ZLOG_WARNING, "failed to change socket attribute"); + } if (wp->listen_address_domain == FPM_AF_UNIX) { if (fpm_socket_unix_test_connect((struct sockaddr_un *)sa, socklen) == 0) { zlog(ZLOG_ERROR, "An another FPM instance seems to already listen on %s", ((struct sockaddr_un *) sa)->sun_path); + close(sock); return -1; } unlink( ((struct sockaddr_un *) sa)->sun_path); @@ -192,6 +195,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct if (wp->listen_address_domain == FPM_AF_UNIX) { umask(saved_umask); } + close(sock); return -1; } @@ -203,6 +207,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct if (wp->socket_uid != -1 || wp->socket_gid != -1) { if (0 > chown(path, wp->socket_uid, wp->socket_gid)) { zlog(ZLOG_SYSERROR, "failed to chown() the socket '%s'", wp->config->listen_address); + close(sock); return -1; } } @@ -210,6 +215,7 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct if (0 > listen(sock, wp->config->listen_backlog)) { zlog(ZLOG_SYSERROR, "failed to listen to address '%s'", wp->config->listen_address); + close(sock); return -1; } diff --git a/sapi/fpm/fpm/fpm_stdio.c b/sapi/fpm/fpm/fpm_stdio.c index 6a587d00e..10b867d00 100644 --- a/sapi/fpm/fpm/fpm_stdio.c +++ b/sapi/fpm/fpm/fpm_stdio.c @@ -34,6 +34,7 @@ int fpm_stdio_init_main() /* {{{ */ if (0 > dup2(fd, STDIN_FILENO) || 0 > dup2(fd, STDOUT_FILENO)) { zlog(ZLOG_SYSERROR, "failed to init stdio: dup2()"); + close(fd); return -1; } close(fd); @@ -294,7 +295,9 @@ int fpm_stdio_open_error_log(int reopen) /* {{{ */ zlog_set_fd(fpm_globals.error_log_fd); } } - fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); + if (0 > fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)) { + zlog(ZLOG_WARNING, "failed to change attribute of error_log"); + } return 0; } /* }}} */ diff --git a/sapi/fpm/fpm/fpm_worker_pool.c b/sapi/fpm/fpm/fpm_worker_pool.c index 123f9893f..ebe1866c8 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.c +++ b/sapi/fpm/fpm/fpm_worker_pool.c @@ -18,6 +18,21 @@ struct fpm_worker_pool_s *fpm_worker_all_pools; +void fpm_worker_pool_free(struct fpm_worker_pool_s *wp) /* {{{ */ +{ + if (wp->config) { + free(wp->config); + } + if (wp->user) { + free(wp->user); + } + if (wp->home) { + free(wp->home); + } + free(wp); +} +/* }}} */ + static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */ { struct fpm_worker_pool_s *wp, *wp_next; @@ -29,10 +44,7 @@ static void fpm_worker_pool_cleanup(int which, void *arg) /* {{{ */ if ((which & FPM_CLEANUP_CHILD) == 0 && fpm_globals.parent_pid == getpid()) { fpm_scoreboard_free(wp->scoreboard); } - free(wp->config); - free(wp->user); - free(wp->home); - free(wp); + fpm_worker_pool_free(wp); } fpm_worker_all_pools = NULL; } diff --git a/sapi/fpm/fpm/fpm_worker_pool.h b/sapi/fpm/fpm/fpm_worker_pool.h index 6688e6d3b..05c993de4 100644 --- a/sapi/fpm/fpm/fpm_worker_pool.h +++ b/sapi/fpm/fpm/fpm_worker_pool.h @@ -45,6 +45,7 @@ struct fpm_worker_pool_s { }; struct fpm_worker_pool_s *fpm_worker_pool_alloc(); +void fpm_worker_pool_free(struct fpm_worker_pool_s *wp); int fpm_worker_pool_init_main(); extern struct fpm_worker_pool_s *fpm_worker_all_pools; |