summaryrefslogtreecommitdiff
path: root/sapi/apache2handler
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/apache2handler')
-rw-r--r--sapi/apache2handler/apache_config.c23
-rw-r--r--sapi/apache2handler/mod_php7.c2
-rw-r--r--sapi/apache2handler/php_apache.h10
-rw-r--r--sapi/apache2handler/php_functions.c2
-rw-r--r--sapi/apache2handler/sapi_apache2.c112
5 files changed, 124 insertions, 25 deletions
diff --git a/sapi/apache2handler/apache_config.c b/sapi/apache2handler/apache_config.c
index 636eee2d4b..38ff99aa7b 100644
--- a/sapi/apache2handler/apache_config.c
+++ b/sapi/apache2handler/apache_config.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -135,6 +135,14 @@ static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, zval *zv,
}
}
+void config_entry_ctor(zval *zv)
+{
+ php_dir_entry *pe = (php_dir_entry*)Z_PTR_P(zv);
+ php_dir_entry *npe = malloc(sizeof(php_dir_entry));
+
+ memcpy(npe, pe, sizeof(php_dir_entry));
+ ZVAL_PTR(zv, npe);
+}
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
{
@@ -142,12 +150,10 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
n = create_php_config(p, "merge_php_config");
/* copy old config */
- zend_hash_copy(&n->config, &d->config, NULL);
-//??? zend_hash_copy(&n->config, &d->config, NULL, NULL, sizeof(php_dir_entry));
+ zend_hash_copy(&n->config, &d->config, config_entry_ctor);
/* merge new config */
phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n));
- zend_hash_merge_ex(&n->config, &e->config, NULL, should_overwrite_per_dir_entry, NULL);
-//??? zend_hash_merge_ex(&n->config, &e->config, NULL, sizeof(php_dir_entry), (merge_checker_func_t) should_overwrite_per_dir_entry, NULL);
+ zend_hash_merge_ex(&n->config, &e->config, config_entry_ctor, should_overwrite_per_dir_entry, NULL);
return n;
}
@@ -197,12 +203,17 @@ static apr_status_t destroy_php_config(void *data)
return APR_SUCCESS;
}
+static void config_entry_dtor(zval *zv)
+{
+ free((php_dir_entry*)Z_PTR_P(zv));
+}
+
void *create_php_config(apr_pool_t *p, char *dummy)
{
php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx));
phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy));
- zend_hash_init(&newx->config, 0, NULL, NULL, 1);
+ zend_hash_init(&newx->config, 0, NULL, config_entry_dtor, 1);
apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null);
return (void *) newx;
}
diff --git a/sapi/apache2handler/mod_php7.c b/sapi/apache2handler/mod_php7.c
index cf6fdaae12..fd7185f856 100644
--- a/sapi/apache2handler/mod_php7.c
+++ b/sapi/apache2handler/mod_php7.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h
index 489892cb60..69c01bbe02 100644
--- a/sapi/apache2handler/php_apache.h
+++ b/sapi/apache2handler/php_apache.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -24,10 +24,16 @@
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
+#include "http_log.h"
#include "php.h"
#include "main/php_streams.h"
+/* Enable per-module logging in Apache 2.4+ */
+#ifdef APLOG_USE_MODULE
+APLOG_USE_MODULE(php7);
+#endif
+
/* Declare this so we can get to it from outside the sapi_apache2.c file */
extern module AP_MODULE_DECLARE_DATA php7_module;
@@ -80,7 +86,7 @@ extern zend_module_entry apache2_module_entry;
#ifdef ZTS
extern int php_apache2_info_id;
#define AP2(v) ZEND_TSRMG(php_apache2_info_id, php_apache2_info_struct *, v)
-ZEND_TSRMLS_CACHE_EXTERN();
+ZEND_TSRMLS_CACHE_EXTERN()
#else
extern php_apache2_info_struct php_apache2_info;
#define AP2(v) (php_apache2_info.v)
diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c
index 3c4cbd9f7b..9ba09da66e 100644
--- a/sapi/apache2handler/php_functions.c
+++ b/sapi/apache2handler/php_functions.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c
index 42861bcf04..12a9e71716 100644
--- a/sapi/apache2handler/sapi_apache2.c
+++ b/sapi/apache2handler/sapi_apache2.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -66,7 +66,34 @@
/* A way to specify the location of the php.ini dir in an apache directive */
char *apache2_php_ini_path_override = NULL;
#if defined(PHP_WIN32) && defined(ZTS)
-ZEND_TSRMLS_CACHE_DEFINE();
+ZEND_TSRMLS_CACHE_DEFINE()
+#endif
+
+/* if apache's version is newer than 2.2.31 or 2.4.16 */
+#if MODULE_MAGIC_COOKIE == 0x41503232UL && AP_MODULE_MAGIC_AT_LEAST(20051115,40) || \
+ MODULE_MAGIC_COOKIE == 0x41503234UL && AP_MODULE_MAGIC_AT_LEAST(20120211,47)
+#define php_ap_map_http_request_error ap_map_http_request_error
+#else
+static int php_ap_map_http_request_error(apr_status_t rv, int status)
+{
+ switch (rv) {
+ case AP_FILTER_ERROR: {
+ return AP_FILTER_ERROR;
+ }
+ case APR_ENOSPC: {
+ return HTTP_REQUEST_ENTITY_TOO_LARGE;
+ }
+ case APR_ENOTIMPL: {
+ return HTTP_NOT_IMPLEMENTED;
+ }
+ case APR_ETIMEDOUT: {
+ return HTTP_REQUEST_TIME_OUT;
+ }
+ default: {
+ return status;
+ }
+ }
+}
#endif
static size_t
@@ -123,15 +150,15 @@ php_apache_sapi_header_handler(sapi_header_struct *sapi_header, sapi_header_op_e
}
ctx->content_type = estrdup(val);
} else if (!strcasecmp(sapi_header->header, "content-length")) {
-#ifdef PHP_WIN32
-# ifdef APR_HAS_LARGE_FILES
- ap_set_content_length(ctx->r, (apr_off_t) _strtoui64(val, (char **)NULL, 10));
-# else
- ap_set_content_length(ctx->r, (apr_off_t) strtol(val, (char **)NULL, 10));
-# endif
-#else
- ap_set_content_length(ctx->r, (apr_off_t) strtol(val, (char **)NULL, 10));
-#endif
+ apr_off_t clen = 0;
+
+ if (APR_SUCCESS != apr_strtoff(&clen, val, (char **) NULL, 10)) {
+ /* We'll fall back to strtol, since that's what we used to
+ * do anyway. */
+ clen = (apr_off_t) strtol(val, (char **) NULL, 10);
+ }
+
+ ap_set_content_length(ctx->r, clen);
} else if (op == SAPI_HEADER_REPLACE) {
apr_table_set(ctx->r->headers_out, sapi_header->header, val);
} else {
@@ -184,6 +211,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
php_struct *ctx = SG(server_context);
request_rec *r;
apr_bucket_brigade *brigade;
+ apr_status_t ret;
r = ctx->r;
brigade = ctx->brigade;
@@ -195,7 +223,7 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
* need to make sure that if data is available we fill the buffer completely.
*/
- while (ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len) == APR_SUCCESS) {
+ while ((ret=ap_get_brigade(r->input_filters, brigade, AP_MODE_READBYTES, APR_BLOCK_READ, len)) == APR_SUCCESS) {
apr_brigade_flatten(brigade, buf, &len);
apr_brigade_cleanup(brigade);
tlen += len;
@@ -206,6 +234,14 @@ php_apache_sapi_read_post(char *buf, size_t count_bytes)
len = count_bytes - tlen;
}
+ if (ret != APR_SUCCESS) {
+ if (APR_STATUS_IS_TIMEUP(ret)) {
+ SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_REQUEST_TIME_OUT);
+ } else {
+ SG(sapi_headers).http_response_code = php_ap_map_http_request_error(ret, HTTP_BAD_REQUEST);
+ }
+ }
+
return tlen;
}
@@ -314,16 +350,52 @@ php_apache_sapi_flush(void *server_context)
}
}
-static void php_apache_sapi_log_message(char *msg)
+static void php_apache_sapi_log_message(char *msg, int syslog_type_int)
{
php_struct *ctx;
+ int aplog_type = APLOG_ERR;
ctx = SG(server_context);
+ switch (syslog_type_int) {
+#if LOG_EMERG != LOG_CRIT
+ case LOG_EMERG:
+ aplog_type = APLOG_EMERG;
+ break;
+#endif
+#if LOG_ALERT != LOG_CRIT
+ case LOG_ALERT:
+ aplog_type = APLOG_ALERT;
+ break;
+#endif
+ case LOG_CRIT:
+ aplog_type = APLOG_CRIT;
+ break;
+ case LOG_ERR:
+ aplog_type = APLOG_ERR;
+ break;
+ case LOG_WARNING:
+ aplog_type = APLOG_WARNING;
+ break;
+ case LOG_NOTICE:
+ aplog_type = APLOG_NOTICE;
+ break;
+#if LOG_INFO != LOG_NOTICE
+ case LOG_INFO:
+ aplog_type = APLOG_INFO;
+ break;
+#endif
+#if LOG_NOTICE != LOG_DEBUG
+ case LOG_DEBUG:
+ aplog_type = APLOG_DEBUG;
+ break;
+#endif
+ }
+
if (ctx == NULL) { /* we haven't initialized our ctx yet, oh well */
ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, 0, NULL, "%s", msg);
} else {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, "%s", msg);
+ ap_log_rerror(APLOG_MARK, aplog_type, 0, ctx->r, "%s", msg);
}
}
@@ -332,7 +404,7 @@ static void php_apache_sapi_log_message_ex(char *msg, request_rec *r)
if (r) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, msg, r->filename);
} else {
- php_apache_sapi_log_message(msg);
+ php_apache_sapi_log_message(msg, -1);
}
}
@@ -455,6 +527,9 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
(void)ts_resource(0);
ZEND_TSRMLS_CACHE_UPDATE();
#endif
+
+ zend_signal_startup();
+
sapi_startup(&apache2_sapi_module);
apache2_sapi_module.startup(&apache2_sapi_module);
apr_pool_cleanup_register(pconf, NULL, php_apache_server_shutdown, apr_pool_cleanup_null);
@@ -651,6 +726,13 @@ zend_first_try {
brigade = ctx->brigade;
}
+ if (SG(request_info).content_length > SG(read_post_bytes)) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Error while attempting to read POST data: %d", SG(sapi_headers).http_response_code);
+ apr_brigade_cleanup(brigade);
+ PHPAP_INI_OFF;
+ return SG(sapi_headers).http_response_code;
+ }
+
if (AP2(last_modified)) {
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);