summaryrefslogtreecommitdiff
path: root/post_handler.c
diff options
context:
space:
mode:
authorStefan Esser2012-01-14 19:32:14 +0100
committerStefan Esser2012-01-14 19:32:14 +0100
commit3b6c6af3faa6a66e4f5337a769baed32f404b82b (patch)
tree54c4cfe5a6a764fe44e6faac7b3eba21bcb9059f /post_handler.c
parent491c7e914bb972e097565d0fd40141ebb10b6107 (diff)
Use new suhosin_getenv() function in all places
Add protection against mbstring Add detection of incompatible extensions that change POST handlers
Diffstat (limited to 'post_handler.c')
-rw-r--r--post_handler.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/post_handler.c b/post_handler.c
index c097a06..b405ae2 100644
--- a/post_handler.c
+++ b/post_handler.c
@@ -86,6 +86,40 @@ static void suhosin_post_handler_modification(sapi_post_entry *spe)
86 efree(content_type); 86 efree(content_type);
87} 87}
88 88
89static int (*old_OnUpdate_mbstring_encoding_translation)(zend_ini_entry *entry, char *new_value, uint new_value_length, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage TSRMLS_DC) = NULL;
90
91/* {{{ static PHP_INI_MH(suhosin_OnUpdate_mbstring_encoding_translation) */
92static PHP_INI_MH(suhosin_OnUpdate_mbstring_encoding_translation)
93{
94 zend_bool *p;
95#ifndef ZTS
96 char *base = (char *) mh_arg2;
97#else
98 char *base;
99
100 base = (char *) ts_resource(*((int *) mh_arg2));
101#endif
102
103 p = (zend_bool *) (base+(size_t) mh_arg1);
104
105 if (new_value_length == 2 && strcasecmp("on", new_value) == 0) {
106 *p = (zend_bool) 1;
107 }
108 else if (new_value_length == 3 && strcasecmp("yes", new_value) == 0) {
109 *p = (zend_bool) 1;
110 }
111 else if (new_value_length == 4 && strcasecmp("true", new_value) == 0) {
112 *p = (zend_bool) 1;
113 }
114 else {
115 *p = (zend_bool) atoi(new_value);
116 }
117 if (*p) {
118 suhosin_log(S_VARS, "Dynamic configuration (maybe a .htaccess file) tried to activate mbstring.encoding_translation which is incompatible with suhosin");
119 }
120 return SUCCESS;
121}
122/* }}} */
89 123
90/* {{{ php_post_entries[] 124/* {{{ php_post_entries[]
91 */ 125 */
@@ -99,6 +133,7 @@ static sapi_post_entry suhosin_post_entries[] = {
99void suhosin_hook_post_handlers(TSRMLS_D) 133void suhosin_hook_post_handlers(TSRMLS_D)
100{ 134{
101 HashTable tempht; 135 HashTable tempht;
136 zend_ini_entry *ini_entry;
102 137
103#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) 138#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0)
104 sapi_unregister_post_entry(&suhosin_post_entries[0] TSRMLS_CC); 139 sapi_unregister_post_entry(&suhosin_post_entries[0] TSRMLS_CC);
@@ -117,12 +152,30 @@ void suhosin_hook_post_handlers(TSRMLS_D)
117 zend_hash_destroy(&tempht); 152 zend_hash_destroy(&tempht);
118 /* And now we can overwrite the destructor for post entries */ 153 /* And now we can overwrite the destructor for post entries */
119 SG(known_post_content_types).pDestructor = suhosin_post_handler_modification; 154 SG(known_post_content_types).pDestructor = suhosin_post_handler_modification;
155
156 /* we have to stop mbstring from replacing our post handler */
157 if (zend_hash_find(EG(ini_directives), "mbstring.encoding_translation", sizeof("mbstring.encoding_translation"), (void **) &ini_entry) == FAILURE) {
158 return;
159 }
160 /* replace OnUpdate_mbstring_encoding_translation handler */
161 old_OnUpdate_mbstring_encoding_translation = ini_entry->on_modify;
162 ini_entry->on_modify = suhosin_OnUpdate_mbstring_encoding_translation;
120} 163}
121 164
122void suhosin_unhook_post_handlers() 165void suhosin_unhook_post_handlers()
123{ 166{
167 zend_ini_entry *ini_entry;
168
124 /* Restore to an empty destructor */ 169 /* Restore to an empty destructor */
125 SG(known_post_content_types).pDestructor = NULL; 170 SG(known_post_content_types).pDestructor = NULL;
171
172 /* Now restore the ini entry handler */
173 if (zend_hash_find(EG(ini_directives), "mbstring.encoding_translation", sizeof("mbstring.encoding_translation"), (void **) &ini_entry) == FAILURE) {
174 return;
175 }
176 /* replace OnUpdate_mbstring_encoding_translation handler */
177 ini_entry->on_modify = old_OnUpdate_mbstring_encoding_translation;
178 old_OnUpdate_mbstring_encoding_translation = NULL;
126} 179}
127 180
128/* 181/*