From 68960966324f4701a1f402e97f17ca7870a317a4 Mon Sep 17 00:00:00 2001 From: Ben Fuhrmannek Date: Thu, 18 Dec 2014 12:06:55 +0100 Subject: removed compatibility to PHP version < 5.4 (by ifdef) --- ex_imp.c | 8 ++++---- execute.c | 17 +++++++++++------ header.c | 8 ++++---- log.c | 8 ++++---- php_suhosin.h | 10 +++++----- post_handler.c | 6 +++--- rfc1867.c | 2 +- rfc1867_new.c | 2 +- session.c | 16 ++++++++-------- sha256.c | 2 +- suhosin.c | 6 +++--- treat_data.c | 6 +++--- 12 files changed, 48 insertions(+), 43 deletions(-) diff --git a/ex_imp.c b/ex_imp.c index 441314d..7122927 100644 --- a/ex_imp.c +++ b/ex_imp.c @@ -86,7 +86,7 @@ static int php_valid_var_name(char *var_name, int len) /* {{{ */ Imports variables into symbol table from an array */ PHP_FUNCTION(suhosin_extract) { -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 zval *var_array, *prefix = NULL; long extract_type = EXTR_OVERWRITE; zval **entry, *data; @@ -422,14 +422,14 @@ PHP_FUNCTION(suhosin_extract) -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 /* import_request_variables() has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. */ #define SUHOSIN_HAVE_IRV 1 #endif #ifdef SUHOSIN_HAVE_IRV -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 static int copy_request_variable(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) { zval *prefix, new_key; @@ -527,7 +527,7 @@ static int copy_request_variable(void *pDest, int num_args, va_list args, zend_h Import GET/POST/Cookie variables into the global scope */ PHP_FUNCTION(suhosin_import_request_variables) { -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 char *types; int types_len; zval *prefix = NULL; diff --git a/execute.c b/execute.c index aa37fb9..37abdfd 100644 --- a/execute.c +++ b/execute.c @@ -859,7 +859,8 @@ int ih_mail(IH_HANDLER_PARAMS) int ih_querycheck(IH_HANDLER_PARAMS) { -#ifdef PHP_ATLEAST_5_3 +// #ifdef PHP_ATLEAST_5_3 +#if 1 void **p = zend_vm_stack_top(TSRMLS_C) - 1; #else void **p = EG(argument_stack).top_element-2; @@ -1020,7 +1021,8 @@ int ih_querycheck(IH_HANDLER_PARAMS) int ih_fixusername(IH_HANDLER_PARAMS) { -#ifdef PHP_ATLEAST_5_3 +// #ifdef PHP_ATLEAST_5_3 +#if 1 void **p = zend_vm_stack_top(TSRMLS_C) - 1; #else void **p = EG(argument_stack).top_element-2; @@ -1115,7 +1117,8 @@ int ih_fixusername(IH_HANDLER_PARAMS) static int ih_function_exists(IH_HANDLER_PARAMS) { -#ifndef PHP_ATLEAST_5_3 +// #ifndef PHP_ATLEAST_5_3 +#if 1 zval **function_name; #endif zend_function *func; @@ -1123,7 +1126,8 @@ static int ih_function_exists(IH_HANDLER_PARAMS) zend_bool retval; int func_name_len; -#ifndef PHP_ATLEAST_5_3 +// #ifndef PHP_ATLEAST_5_3 +#if 1 if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &function_name)==FAILURE) { ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(1); } @@ -1559,7 +1563,8 @@ static int ih_rand(IH_HANDLER_PARAMS) static int ih_getrandmax(IH_HANDLER_PARAMS) { -#ifdef PHP_ATLEAST_5_3 +// #ifdef PHP_ATLEAST_5_3 +#if 1 if (zend_parse_parameters_none() == FAILURE) { return(0); } @@ -1737,7 +1742,7 @@ static void suhosin_execute_internal(zend_execute_data *execute_data_ptr, int re #if PHP_VERSION_ID < 50500 #ifdef ZEND_ENGINE_2 -# if PHP_VERSION_ID < 50400 +# if 0 // PHP_VERSION_ID < 50400 return_value = (*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.u.var)).var.ptr; # else return_value = (*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.var)).var.ptr; diff --git a/header.c b/header.c index ddb1296..1a85015 100644 --- a/header.c +++ b/header.c @@ -32,7 +32,7 @@ #include "SAPI.h" #include "php_variables.h" -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 static int (*orig_header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) = NULL; #else static int (*orig_header_handler)(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) = NULL; @@ -190,7 +190,7 @@ char *suhosin_cookie_decryptor(TSRMLS_D) /* {{{ suhosin_header_handler */ -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 int suhosin_header_handler(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers TSRMLS_DC) #else int suhosin_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct *sapi_headers TSRMLS_DC) @@ -199,7 +199,7 @@ int suhosin_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct int retval = SAPI_HEADER_ADD, i; char *tmp; -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 if (op != SAPI_HEADER_ADD && op != SAPI_HEADER_REPLACE) { goto suhosin_skip_header_handling; } @@ -294,7 +294,7 @@ int suhosin_header_handler(sapi_header_struct *sapi_header, sapi_headers_struct suhosin_skip_header_handling: /* If existing call the sapi header handler */ if (orig_header_handler) { -#if PHP_VERSION_ID >= 50300 +#if 1 //PHP_VERSION_ID >= 50300 retval = orig_header_handler(sapi_header, op, sapi_headers TSRMLS_CC); #else retval = orig_header_handler(sapi_header, sapi_headers TSRMLS_CC); diff --git a/log.c b/log.c index 1a4c783..ed83c24 100644 --- a/log.c +++ b/log.c @@ -287,7 +287,7 @@ log_sapi: /* SAPI Logging activated? */ SDEBUG("(suhosin_log) log_syslog: %ld - log_sapi: %ld - log_script: %ld - log_phpscript: %ld", SUHOSIN_G(log_syslog), SUHOSIN_G(log_sapi), SUHOSIN_G(log_script), SUHOSIN_G(log_phpscript)); if (((SUHOSIN_G(log_sapi)|S_INTERNAL) & loglevel)!=0) { -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 sapi_module.log_message(buf); #else sapi_module.log_message(buf TSRMLS_CC); @@ -372,7 +372,7 @@ log_phpscript: zval *result = NULL; long orig_execution_depth = SUHOSIN_G(execution_depth); -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 zend_bool orig_safe_mode = PG(safe_mode); #endif char *orig_basedir = PG(open_basedir); @@ -411,7 +411,7 @@ SDEBUG("scriptname %s", SUHOSIN_G(log_phpscriptname)); SUHOSIN_G(execution_depth) = 0; if (SUHOSIN_G(log_phpscript_is_safe)) { -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 PG(safe_mode) = 0; #endif PG(open_basedir) = NULL; @@ -420,7 +420,7 @@ SDEBUG("scriptname %s", SUHOSIN_G(log_phpscriptname)); zend_execute(new_op_array TSRMLS_CC); SUHOSIN_G(execution_depth) = orig_execution_depth; -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 PG(safe_mode) = orig_safe_mode; #endif PG(open_basedir) = orig_basedir; diff --git a/php_suhosin.h b/php_suhosin.h index 88890fb..ccf1a91 100644 --- a/php_suhosin.h +++ b/php_suhosin.h @@ -120,7 +120,7 @@ protected_varname: } -#if PHP_VERSION_ID < 50203 +#if 0 //PHP_VERSION_ID < 50203 static inline int php_varname_check(char *name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */ { if (name_len == sizeof("GLOBALS") - 1 && !memcmp(name, "GLOBALS", sizeof("GLOBALS") - 1)) { @@ -453,8 +453,8 @@ size_t suhosin_strnspn(const char *input, size_t n, const char *accept); size_t suhosin_strncspn(const char *input, size_t n, const char *reject); /* Add pseudo refcount macros for PHP version < 5.3 */ -#ifndef Z_REFCOUNT_PP - +// #ifndef Z_REFCOUNT_PP +#if 0 #define Z_REFCOUNT_PP(ppz) Z_REFCOUNT_P(*(ppz)) #define Z_SET_REFCOUNT_PP(ppz, rc) Z_SET_REFCOUNT_P(*(ppz), rc) #define Z_ADDREF_PP(ppz) Z_ADDREF_P(*(ppz)) @@ -522,9 +522,9 @@ static zend_always_inline zend_bool zval_set_isref_to_p(zval* pz, zend_bool isre return pz->is_ref = isref; } -#else +// #else -#define PHP_ATLEAST_5_3 true +// #define PHP_ATLEAST_5_3 true #endif diff --git a/post_handler.c b/post_handler.c index 737f33f..388a096 100644 --- a/post_handler.c +++ b/post_handler.c @@ -46,7 +46,7 @@ SAPI_POST_HANDLER_FUNC(suhosin_std_post_handler) { char *var, *val, *e, *s, *p; zval *array_ptr = (zval *) arg; -#if PHP_VERSION_ID >= 50311 +#if 1 //PHP_VERSION_ID >= 50311 long count = 0; #endif if (SG(request_info).post_data == NULL) { @@ -61,7 +61,7 @@ last_value: if ((val = memchr(s, '=', (p - s)))) { /* have a value */ unsigned int val_len, new_val_len; -#if PHP_VERSION_ID >= 50311 +#if 1 //PHP_VERSION_ID >= 50311 if (++count > PG(max_input_vars)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); return; @@ -266,7 +266,7 @@ void suhosin_hook_post_handlers(TSRMLS_D) HashTable tempht; zend_ini_entry *ini_entry; -#if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) +#if 1 //PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) sapi_unregister_post_entry(&suhosin_post_entries[0] TSRMLS_CC); sapi_unregister_post_entry(&suhosin_post_entries[1] TSRMLS_CC); sapi_register_post_entries(suhosin_post_entries TSRMLS_CC); diff --git a/rfc1867.c b/rfc1867.c index e19c677..e1e13f0 100644 --- a/rfc1867.c +++ b/rfc1867.c @@ -36,7 +36,7 @@ #include "php_ini.h" #include "ext/standard/php_string.h" -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 #define DEBUG_FILE_UPLOAD ZEND_DEBUG diff --git a/rfc1867_new.c b/rfc1867_new.c index 720e3ff..9831e8a 100644 --- a/rfc1867_new.c +++ b/rfc1867_new.c @@ -35,7 +35,7 @@ #include "suhosin_rfc1867.h" #include "ext/standard/php_string.h" -#if PHP_VERSION_ID >= 50400 +#if 1 //PHP_VERSION_ID >= 50400 #define DEBUG_FILE_UPLOAD ZEND_DEBUG diff --git a/session.c b/session.c index 548786f..1044977 100644 --- a/session.c +++ b/session.c @@ -59,7 +59,7 @@ static int suhosin_get_session_var(char *name, size_t namelen, zval ***state_var if (SESSION_G(http_session_vars) && SESSION_G(http_session_vars)->type == IS_ARRAY) { ret = zend_hash_find(Z_ARRVAL_P(SESSION_G(http_session_vars)), name, namelen + 1, (void **) state_var); -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 /* If register_globals is enabled, and * if there is an entry for the slot in $_SESSION, and * if that entry is still set to NULL, and @@ -123,7 +123,7 @@ static void suhosin_send_cookie(TSRMLS_D) /* The following is requires to be 100% compatible to PHP versions where the hash extension is not available by default */ -#if (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) +#if 1 //(PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) if (zend_hash_find(EG(ini_directives), "session.hash_bits_per_character", sizeof("session.hash_bits_per_character"), (void **) &ini_entry) == SUCCESS) { #ifndef ZTS base = (char *) ini_entry->mh_arg2; @@ -155,7 +155,7 @@ static int suhosin_hook_s_read(void **mod_data, const char *key, char **val, int /* protect dumb session handlers */ if (key == NULL || !key[0] || (*mod_data == NULL -#if PHP_VERSION_ID >= 50400 +#if 1 //PHP_VERSION_ID >= 50400 && !SESSION_G(mod_user_implemented) #endif )) { @@ -169,7 +169,7 @@ regenerate: goto regenerate; } } -#if (PHP_MAJOR_VERSION < 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 2) +#if 0 //(PHP_MAJOR_VERSION < 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 2) else if (strpbrk(KEY, "\r\n\t <>'\"\\")) { suhosin_log(S_SESSION, "session id ('%s') contains invalid chars - regenerating", KEY); if (!SUHOSIN_G(simulation)) { @@ -209,7 +209,7 @@ static int suhosin_hook_s_write(void **mod_data, const char *key, const char *va /* protect dumb session handlers */ if (key == NULL || !key[0] || val == NULL || strlen(key) > SUHOSIN_G(session_max_id_length) || (*mod_data == NULL -#if PHP_VERSION_ID >= 50400 +#if 1 //PHP_VERSION_ID >= 50400 && !SESSION_G(mod_user_implemented) #endif )) { @@ -257,7 +257,7 @@ static int suhosin_hook_s_destroy(void **mod_data, const char *key TSRMLS_DC) /* protect dumb session handlers */ if (key == NULL || !key[0] || strlen(key) > SUHOSIN_G(session_max_id_length) || (*mod_data == NULL -#if PHP_VERSION_ID >= 50400 +#if 1 //PHP_VERSION_ID >= 50400 && !SESSION_G(mod_user_implemented) #endif )) { @@ -343,7 +343,7 @@ void suhosin_hook_session(TSRMLS_D) return; } /* retrieve globals from module entry struct if possible */ -#if PHP_VERSION_ID >= 50200 +#if 1 //PHP_VERSION_ID >= 50200 #ifdef ZTS if (session_globals_id == 0) { session_globals_id = *module->globals_id_ptr; @@ -401,7 +401,7 @@ void suhosin_hook_session(TSRMLS_D) suhosin_hook_session_module(TSRMLS_C); /* Protect the PHP serializer from ! attacks */ -# if PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) +#if 1 //PHP_MAJOR_VERSION > 5 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) serializer = (ps_serializer *) SESSION_G(serializer); if (serializer != NULL && strcmp(serializer->name, "php")==0) { serializer->encode = suhosin_session_encode; diff --git a/sha256.c b/sha256.c index 275dccd..d91e575 100644 --- a/sha256.c +++ b/sha256.c @@ -86,7 +86,7 @@ static PHP_FUNCTION(suhosin_sha256_file) return; } -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { RETURN_FALSE; } diff --git a/suhosin.c b/suhosin.c index 5b24789..b1bc47b 100644 --- a/suhosin.c +++ b/suhosin.c @@ -1058,10 +1058,10 @@ PHP_MINIT_FUNCTION(suhosin) php_register_info_logo(SUHOSIN_LOGO_GUID, "image/jpeg", suhosin_logo, sizeof(suhosin_logo)); #endif -#if PHP_MAJOR_VERSION < 5 -#error Suhosin Extension is not designed to run with PHP 4 and below. +#if PHP_VERSION_ID < 50400 //PHP_MAJOR_VERSION < 5 +#error Suhosin Extension is not designed to run with PHP versions lower than 5.4. #endif -#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION <= 2 && !SUHOSIN_DEBUG +#if 0 //PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION <= 2 && !SUHOSIN_DEBUG php_error_docref(NULL TSRMLS_CC, E_WARNING, "Suhosin Extension does not officially support PHP 5.2 and below anymore, because it is discontinued. Use it at your own risk."); #endif diff --git a/treat_data.c b/treat_data.c index 15e721d..9dc86d1 100644 --- a/treat_data.c +++ b/treat_data.c @@ -39,7 +39,7 @@ SAPI_TREAT_DATA_FUNC(suhosin_treat_data) int free_buffer = 0; char *strtok_buf = NULL; -#if PHP_VERSION_ID >= 50311 +#if 1 //PHP_VERSION_ID >= 50311 long count = 0; #endif @@ -148,7 +148,7 @@ SAPI_TREAT_DATA_FUNC(suhosin_treat_data) } val = strchr(var, '='); -#if PHP_VERSION_ID >= 50311 +#if 1 //PHP_VERSION_ID >= 50311 if (++count > PG(max_input_vars)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Input variables exceeded %ld. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars)); break; @@ -210,7 +210,7 @@ SAPI_TREAT_DATA_FUNC(suhosin_treat_data) void suhosin_hook_treat_data() { -#if PHP_VERSION_ID < 50400 +#if 0 //PHP_VERSION_ID < 50400 sapi_register_treat_data(suhosin_treat_data); #else TSRMLS_FETCH(); -- cgit v1.3