summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Esser2012-01-14 18:40:39 +0100
committerStefan Esser2012-01-14 18:40:39 +0100
commitbaed654dfa7c0e04795307b6567d4141fd6365c3 (patch)
tree3331290765f261825a708309a36632e2f0707bba
parent73b1968ee30f6d9d2dae497544b910e68e114bfa (diff)
detect runtime modification of post handlers
-rw-r--r--php_suhosin.h1
-rw-r--r--post_handler.c23
-rw-r--r--suhosin.c1
3 files changed, 25 insertions, 0 deletions
diff --git a/php_suhosin.h b/php_suhosin.h
index 93a6b45..1e2e053 100644
--- a/php_suhosin.h
+++ b/php_suhosin.h
@@ -307,6 +307,7 @@ char *suhosin_decrypt_string(char *str, int padded_len, char *var, int vlen, cha
307char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, char *cryptkey TSRMLS_DC); 307char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, char *cryptkey TSRMLS_DC);
308char *suhosin_cookie_decryptor(TSRMLS_D); 308char *suhosin_cookie_decryptor(TSRMLS_D);
309void suhosin_hook_post_handlers(TSRMLS_D); 309void suhosin_hook_post_handlers(TSRMLS_D);
310void suhosin_unhook_post_handlers();
310void suhosin_hook_register_server_variables(); 311void suhosin_hook_register_server_variables();
311void suhosin_hook_header_handler(); 312void suhosin_hook_header_handler();
312void suhosin_unhook_header_handler(); 313void suhosin_unhook_header_handler();
diff --git a/post_handler.c b/post_handler.c
index c36c1a0..c097a06 100644
--- a/post_handler.c
+++ b/post_handler.c
@@ -79,6 +79,14 @@ last_value:
79 } 79 }
80} 80}
81 81
82static void suhosin_post_handler_modification(sapi_post_entry *spe)
83{
84 char *content_type = estrndup(spe->content_type, spe->content_type_len);
85 suhosin_log(S_VARS, "some extension replaces the POST handler for %s - Suhosin's protection will be incomplete", content_type);
86 efree(content_type);
87}
88
89
82/* {{{ php_post_entries[] 90/* {{{ php_post_entries[]
83 */ 91 */
84static sapi_post_entry suhosin_post_entries[] = { 92static sapi_post_entry suhosin_post_entries[] = {
@@ -90,6 +98,8 @@ static sapi_post_entry suhosin_post_entries[] = {
90 98
91void suhosin_hook_post_handlers(TSRMLS_D) 99void suhosin_hook_post_handlers(TSRMLS_D)
92{ 100{
101 HashTable tempht;
102
93#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) 103#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0)
94 sapi_unregister_post_entry(&suhosin_post_entries[0] TSRMLS_CC); 104 sapi_unregister_post_entry(&suhosin_post_entries[0] TSRMLS_CC);
95 sapi_unregister_post_entry(&suhosin_post_entries[1] TSRMLS_CC); 105 sapi_unregister_post_entry(&suhosin_post_entries[1] TSRMLS_CC);
@@ -99,8 +109,21 @@ void suhosin_hook_post_handlers(TSRMLS_D)
99 sapi_unregister_post_entry(&suhosin_post_entries[1]); 109 sapi_unregister_post_entry(&suhosin_post_entries[1]);
100 sapi_register_post_entries(suhosin_post_entries); 110 sapi_register_post_entries(suhosin_post_entries);
101#endif 111#endif
112 /* we want to get notified if another extension deregisters the suhosin post handlers */
113
114 /* we need to tell suhosin patch that there is a new valid destructor */
115 /* therefore we have create HashTable that has this destructor */
116 zend_hash_init(&tempht, 0, NULL, suhosin_post_handler_modification, 0);
117 zend_hash_destroy(&tempht);
118 /* And now we can overwrite the destructor for post entries */
119 SG(known_post_content_types).pDestructor = suhosin_post_handler_modification;
102} 120}
103 121
122void suhosin_unhook_post_handlers()
123{
124 /* Restore to an empty destructor */
125 SG(known_post_content_types).pDestructor = NULL;
126}
104 127
105/* 128/*
106 * Local variables: 129 * Local variables:
diff --git a/suhosin.c b/suhosin.c
index 1b54c39..e111d55 100644
--- a/suhosin.c
+++ b/suhosin.c
@@ -191,6 +191,7 @@ static void suhosin_shutdown(zend_extension *extension)
191{ 191{
192 suhosin_unhook_execute(); 192 suhosin_unhook_execute();
193 suhosin_unhook_header_handler(); 193 suhosin_unhook_header_handler();
194 suhosin_unhook_post_handlers();
194 195
195 if (ze != NULL) { 196 if (ze != NULL) {
196 ze->startup = orig_module_startup; 197 ze->startup = orig_module_startup;