diff --git a/ext/filter/filter.c b/ext/filter/filter.c index 9c380163823cd..50eefb440d67a 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -100,9 +100,9 @@ ZEND_GET_MODULE(filter) static PHP_INI_MH(UpdateDefaultFilter) /* {{{ */ { - int i, size = sizeof(filter_list) / sizeof(filter_list_entry); + int size = sizeof(filter_list) / sizeof(filter_list_entry); - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if ((strcasecmp(ZSTR_VAL(new_value), filter_list[i].name) == 0)) { IF_G(default_filter) = filter_list[i].id; if (IF_G(default_filter) != FILTER_DEFAULT) { @@ -144,9 +144,6 @@ ZEND_TSRMLS_CACHE_UPDATE(); ZVAL_UNDEF(&filter_globals->cookie_array); ZVAL_UNDEF(&filter_globals->env_array); ZVAL_UNDEF(&filter_globals->server_array); -#if 0 - ZVAL_UNDEF(&filter_globals->session_array); -#endif filter_globals->default_filter = FILTER_DEFAULT; } /* }}} */ @@ -189,9 +186,6 @@ PHP_RSHUTDOWN_FUNCTION(filter) VAR_ARRAY_COPY_DTOR(cookie_array) VAR_ARRAY_COPY_DTOR(server_array) VAR_ARRAY_COPY_DTOR(env_array) -#if 0 - VAR_ARRAY_COPY_DTOR(session_array) -#endif return SUCCESS; } /* }}} */ @@ -234,13 +228,10 @@ static unsigned int php_sapi_filter_init(void) ZVAL_UNDEF(&IF_G(cookie_array)); ZVAL_UNDEF(&IF_G(server_array)); ZVAL_UNDEF(&IF_G(env_array)); -#if 0 - ZVAL_UNDEF(&IF_G(session_array)); -#endif return SUCCESS; } -static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval *options, char* charset, bool copy) /* {{{ */ +static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval *options, char* charset) /* {{{ */ { filter_list_entry filter_func; @@ -336,7 +327,7 @@ static unsigned int php_sapi_filter(int arg, const char *var, char **val, size_t /* Register mangled variable */ if (IF_G(default_filter) != FILTER_UNSAFE_RAW) { ZVAL_STRINGL(&new_var, *val, val_len); - php_zval_filter(&new_var, IF_G(default_filter), IF_G(default_filter_flags), NULL, NULL, 0); + php_zval_filter(&new_var, IF_G(default_filter), IF_G(default_filter_flags), NULL, NULL); } else { ZVAL_STRINGL(&new_var, *val, val_len); } @@ -365,7 +356,7 @@ static unsigned int php_sapi_filter(int arg, const char *var, char **val, size_t } /* }}} */ -static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long flags, zval *options, char *charset, bool copy) /* {{{ */ +static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long flags, zval *options, char *charset) /* {{{ */ { if (Z_TYPE_P(value) == IS_ARRAY) { zval *element; @@ -379,14 +370,14 @@ static void php_zval_filter_recursive(zval *value, zend_long filter, zend_long f ZVAL_DEREF(element); if (Z_TYPE_P(element) == IS_ARRAY) { SEPARATE_ARRAY(element); - php_zval_filter_recursive(element, filter, flags, options, charset, copy); + php_zval_filter_recursive(element, filter, flags, options, charset); } else { - php_zval_filter(element, filter, flags, options, charset, copy); + php_zval_filter(element, filter, flags, options, charset); } } ZEND_HASH_FOREACH_END(); Z_UNPROTECT_RECURSION_P(value); } else { - php_zval_filter(value, filter, flags, options, charset, copy); + php_zval_filter(value, filter, flags, options, charset); } } /* }}} */ @@ -458,10 +449,9 @@ PHP_FUNCTION(filter_has_var) static void php_filter_call( zval *filtered, zend_long filter, HashTable *filter_args_ht, zend_long filter_args_long, - const int copy, zend_long filter_flags + zend_long filter_flags ) /* {{{ */ { zval *options = NULL; - zval *option; char *charset = NULL; if (!filter_args_ht) { @@ -476,6 +466,7 @@ static void php_filter_call( filter = filter_args_long; } } else { + zval *option; if ((option = zend_hash_str_find(filter_args_ht, "filter", sizeof("filter") - 1)) != NULL) { filter = zval_get_long(option); } @@ -510,7 +501,7 @@ static void php_filter_call( } return; } - php_zval_filter_recursive(filtered, filter, filter_flags, options, charset, copy); + php_zval_filter_recursive(filtered, filter, filter_flags, options, charset); return; } if (filter_flags & FILTER_REQUIRE_ARRAY) { @@ -523,7 +514,7 @@ static void php_filter_call( return; } - php_zval_filter(filtered, filter, filter_flags, options, charset, copy); + php_zval_filter(filtered, filter, filter_flags, options, charset); if (filter_flags & FILTER_FORCE_ARRAY) { zval tmp; ZVAL_COPY_VALUE(&tmp, filtered); @@ -536,14 +527,13 @@ static void php_filter_call( static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op_long, zval *return_value, bool add_empty ) /* {{{ */ { - zend_string *arg_key; - zval *tmp, *arg_elm; - if (!op_ht) { ZVAL_DUP(return_value, input); - php_filter_call(return_value, -1, NULL, op_long, 0, FILTER_REQUIRE_ARRAY); + php_filter_call(return_value, -1, NULL, op_long, FILTER_REQUIRE_ARRAY); } else { array_init(return_value); + zend_string *arg_key; + zval *arg_elm; ZEND_HASH_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) { if (arg_key == NULL) { @@ -554,6 +544,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op zend_argument_value_error(2, "cannot contain empty keys"); RETURN_THROWS(); } + zval *tmp; if ((tmp = zend_hash_find(Z_ARRVAL_P(input), arg_key)) == NULL) { if (add_empty) { add_assoc_null_ex(return_value, ZSTR_VAL(arg_key), ZSTR_LEN(arg_key)); @@ -565,7 +556,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op php_filter_call(&nval, -1, Z_TYPE_P(arg_elm) == IS_ARRAY ? Z_ARRVAL_P(arg_elm) : NULL, Z_TYPE_P(arg_elm) == IS_ARRAY ? 0 : zval_get_long(arg_elm), - 0, FILTER_REQUIRE_SCALAR + FILTER_REQUIRE_SCALAR ); zend_hash_update(Z_ARRVAL_P(return_value), arg_key, &nval); } @@ -603,10 +594,10 @@ PHP_FUNCTION(filter_input) if (!input || (tmp = zend_hash_find(Z_ARRVAL_P(input), var)) == NULL) { zend_long filter_flags = 0; - zval *option, *opt, *def; if (!filter_args_ht) { filter_flags = filter_args_long; } else { + zval *option, *opt, *def; if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) { filter_flags = zval_get_long(option); } @@ -634,7 +625,7 @@ PHP_FUNCTION(filter_input) ZVAL_DUP(return_value, tmp); - php_filter_call(return_value, filter, filter_args_ht, filter_args_long, 1, FILTER_REQUIRE_SCALAR); + php_filter_call(return_value, filter, filter_args_ht, filter_args_long, FILTER_REQUIRE_SCALAR); } /* }}} */ @@ -660,7 +651,7 @@ PHP_FUNCTION(filter_var) ZVAL_DUP(return_value, data); - php_filter_call(return_value, filter, filter_args_ht, filter_args_long, 1, FILTER_REQUIRE_SCALAR); + php_filter_call(return_value, filter, filter_args_ht, filter_args_long, FILTER_REQUIRE_SCALAR); } /* }}} */ @@ -726,14 +717,14 @@ PHP_FUNCTION(filter_var_array) /* {{{ Returns a list of all supported filters */ PHP_FUNCTION(filter_list) { - int i, size = sizeof(filter_list) / sizeof(filter_list_entry); + int size = sizeof(filter_list) / sizeof(filter_list_entry); if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } array_init(return_value); - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { add_next_index_string(return_value, (char *)filter_list[i].name); } } @@ -742,7 +733,6 @@ PHP_FUNCTION(filter_list) /* {{{ Returns the filter ID belonging to a named filter */ PHP_FUNCTION(filter_id) { - int i; size_t filter_len; int size = sizeof(filter_list) / sizeof(filter_list_entry); char *filter; @@ -751,7 +741,7 @@ PHP_FUNCTION(filter_id) RETURN_THROWS(); } - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (strcmp(filter_list[i].name, filter) == 0) { RETURN_LONG(filter_list[i].id); } diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index d0d60c00ebc63..054b0ed9d6430 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -89,16 +89,17 @@ #define FORMAT_IPV4 4 #define FORMAT_IPV6 6 -static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]); +static bool _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]); -static int php_filter_parse_int(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ +static bool php_filter_parse_int(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ zend_long ctx_value; - int sign = 0, digit = 0; + bool is_negative = false; + int digit = 0; const char *end = str + str_len; switch (*str) { case '-': - sign = 1; + is_negative = true; ZEND_FALLTHROUGH; case '+': str++; @@ -108,43 +109,43 @@ static int php_filter_parse_int(const char *str, size_t str_len, zend_long *ret) if (*str == '0' && str + 1 == end) { /* Special cases: +0 and -0 */ - return 1; + return true; } /* must start with 1..9*/ if (str < end && *str >= '1' && *str <= '9') { - ctx_value = ((sign)?-1:1) * ((*(str++)) - '0'); + ctx_value = (is_negative?-1:1) * ((*(str++)) - '0'); } else { - return -1; + return false; } if ((end - str > MAX_LENGTH_OF_LONG - 1) /* number too long */ || (SIZEOF_LONG == 4 && (end - str == MAX_LENGTH_OF_LONG - 1) && *str > '2')) { /* overflow */ - return -1; + return false; } while (str < end) { if (*str >= '0' && *str <= '9') { digit = (*(str++) - '0'); - if ( (!sign) && ctx_value <= (ZEND_LONG_MAX-digit)/10 ) { + if ( (!is_negative) && ctx_value <= (ZEND_LONG_MAX-digit)/10 ) { ctx_value = (ctx_value * 10) + digit; - } else if ( sign && ctx_value >= (ZEND_LONG_MIN+digit)/10) { + } else if ( is_negative && ctx_value >= (ZEND_LONG_MIN+digit)/10) { ctx_value = (ctx_value * 10) - digit; } else { - return -1; + return false; } } else { - return -1; + return false; } } *ret = ctx_value; - return 1; + return true; } /* }}} */ -static int php_filter_parse_octal(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ +static bool php_filter_parse_octal(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ zend_ulong ctx_value = 0; const char *end = str + str_len; @@ -154,20 +155,20 @@ static int php_filter_parse_octal(const char *str, size_t str_len, zend_long *re if ((ctx_value > ((zend_ulong)(~(zend_long)0)) / 8) || ((ctx_value = ctx_value * 8) > ((zend_ulong)(~(zend_long)0)) - n)) { - return -1; + return false; } ctx_value += n; } else { - return -1; + return false; } } *ret = (zend_long)ctx_value; - return 1; + return true; } /* }}} */ -static int php_filter_parse_hex(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ +static bool php_filter_parse_hex(const char *str, size_t str_len, zend_long *ret) { /* {{{ */ zend_ulong ctx_value = 0; const char *end = str + str_len; zend_ulong n; @@ -180,17 +181,17 @@ static int php_filter_parse_hex(const char *str, size_t str_len, zend_long *ret) } else if (*str >= 'A' && *str <= 'F') { n = ((*(str++)) - ('A' - 10)); } else { - return -1; + return false; } if ((ctx_value > ((zend_ulong)(~(zend_long)0)) / 16) || ((ctx_value = ctx_value * 16) > ((zend_ulong)(~(zend_long)0)) - n)) { - return -1; + return false; } ctx_value += n; } *ret = (zend_long)ctx_value; - return 1; + return true; } /* }}} */ @@ -199,11 +200,11 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ zval *option_val; zend_long min_range, max_range, option_flags; int min_range_set, max_range_set; - int allow_octal = 0, allow_hex = 0; + bool allow_octal = false, allow_hex = false; size_t len; - int error = 0; + bool error = false; zend_long ctx_value; - char *p; + const char *p; /* Parse options */ FETCH_LONG_OPTION(min_range, "min_range"); @@ -217,11 +218,11 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } if (option_flags & FILTER_FLAG_ALLOW_OCTAL) { - allow_octal = 1; + allow_octal = true; } if (option_flags & FILTER_FLAG_ALLOW_HEX) { - allow_hex = 1; + allow_hex = true; } /* Start the validating loop */ @@ -237,8 +238,8 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if (len == 0) { RETURN_VALIDATION_FAILED } - if (php_filter_parse_hex(p, len, &ctx_value) < 0) { - error = 1; + if (!php_filter_parse_hex(p, len, &ctx_value)) { + error = true; } } else if (allow_octal) { /* Support explicit octal prefix notation */ @@ -248,19 +249,19 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ RETURN_VALIDATION_FAILED } } - if (php_filter_parse_octal(p, len, &ctx_value) < 0) { - error = 1; + if (!php_filter_parse_octal(p, len, &ctx_value)) { + error = true; } } else if (len != 0) { - error = 1; + error = true; } } else { - if (php_filter_parse_int(p, len, &ctx_value) < 0) { - error = 1; + if (!php_filter_parse_int(p, len, &ctx_value)) { + error = true; } } - if (error > 0 || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) { + if (error || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) { RETURN_VALIDATION_FAILED } else { zval_ptr_dtor(value); @@ -272,7 +273,7 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { - char *str = Z_STRVAL_P(value); + const char *str = Z_STRVAL_P(value); size_t len = Z_STRLEN_P(value); int ret; @@ -342,7 +343,7 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { size_t len; - char *str, *end; + const char *str, *end; char *num, *p; zval *option_val; char *decimal; @@ -359,7 +360,7 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ double min_range, max_range; int min_range_set, max_range_set; - int first, n; + int n; len = Z_STRLEN_P(value); str = Z_STRVAL_P(value); @@ -398,7 +399,7 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if (str < end && (*str == '+' || *str == '-')) { *p++ = *str++; } - first = 1; + bool first = true; while (1) { n = 0; while (str < end && *str >= '0' && *str <= '9') { @@ -431,7 +432,7 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if (first?(n < 1 || n > 3):(n != 3)) { goto error; } - first = 0; + first = false; str++; } else { goto error; @@ -504,16 +505,16 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } } -static int _php_filter_validate_domain(char * domain, size_t len, zend_long flags) /* {{{ */ +static bool php_filter_validate_domain_ex(const zend_string *domain, zend_long flags) /* {{{ */ { - char *e, *s, *t; + const char *e, *s, *t; size_t l; int hostname = flags & FILTER_FLAG_HOSTNAME; unsigned char i = 1; - s = domain; - l = len; - e = domain + l; + s = ZSTR_VAL(domain); + l = ZSTR_LEN(domain); + e = s + l; t = e - 1; /* Ignore trailing dot */ @@ -524,26 +525,26 @@ static int _php_filter_validate_domain(char * domain, size_t len, zend_long flag /* The total length cannot exceed 253 characters (final dot not included) */ if (l > 253) { - return 0; + return false; } /* First char must be alphanumeric */ if(*s == '.' || (hostname && !isalnum((int)*(unsigned char *)s))) { - return 0; + return false; } while (s < e) { if (*s == '.') { /* The first and the last character of a label must be alphanumeric */ if (*(s + 1) == '.' || (hostname && (!isalnum((int)*(unsigned char *)(s - 1)) || !isalnum((int)*(unsigned char *)(s + 1))))) { - return 0; + return false; } /* Reset label length counter */ i = 1; } else { if (i > 63 || (hostname && (*s != '-' || *(s + 1) == '\0') && !isalnum((int)*(unsigned char *)s))) { - return 0; + return false; } i++; @@ -552,40 +553,40 @@ static int _php_filter_validate_domain(char * domain, size_t len, zend_long flag s++; } - return 1; + return true; } /* }}} */ void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { - if (!_php_filter_validate_domain(Z_STRVAL_P(value), Z_STRLEN_P(value), flags)) { + if (!php_filter_validate_domain_ex(Z_STR_P(value), flags)) { RETURN_VALIDATION_FAILED } } /* }}} */ -static int is_userinfo_valid(zend_string *str) +static bool is_userinfo_valid(const zend_string *str) { - const char *valid = "-._~!$&'()*+,;=:"; const char *p = ZSTR_VAL(str); while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) { + static const char *valid = "-._~!$&'()*+,;=:"; if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) { p++; } else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) { p += 3; } else { - return 0; + return false; } } - return 1; + return true; } -static bool php_filter_is_valid_ipv6_hostname(const char *s, size_t l) +static bool php_filter_is_valid_ipv6_hostname(const zend_string *s) { - const char *e = s + l; + const char *e = ZSTR_VAL(s) + ZSTR_LEN(s); const char *t = e - 1; - return *s == '[' && *t == ']' && _php_filter_validate_ipv6(s + 1, l - 2, NULL); + return *ZSTR_VAL(s) == '[' && *t == ']' && _php_filter_validate_ipv6(ZSTR_VAL(s) + 1, ZSTR_LEN(s) - 2, NULL); } void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ @@ -608,22 +609,17 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if (url->scheme != NULL && (zend_string_equals_literal_ci(url->scheme, "http") || zend_string_equals_literal_ci(url->scheme, "https"))) { - const char *s; - size_t l; if (url->host == NULL) { goto bad_url; } - s = ZSTR_VAL(url->host); - l = ZSTR_LEN(url->host); - if ( /* An IPv6 enclosed by square brackets is a valid hostname.*/ - !php_filter_is_valid_ipv6_hostname(s, l) && + !php_filter_is_valid_ipv6_hostname(url->host) && /* Validate domain. * This includes a loose check for an IPv4 address. */ - !_php_filter_validate_domain(ZSTR_VAL(url->host), l, FILTER_FLAG_HOSTNAME) + !php_filter_validate_domain_ex(url->host, FILTER_FLAG_HOSTNAME) ) { php_url_free(url); RETURN_VALIDATION_FAILED @@ -723,16 +719,16 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } /* }}} */ -static int _php_filter_validate_ipv4(char *str, size_t str_len, int *ip) /* {{{ */ +static bool _php_filter_validate_ipv4(const char *str, size_t str_len, int *ip) /* {{{ */ { const char *end = str + str_len; int num, m; int n = 0; while (str < end) { - int leading_zero; + bool leading_zero; if (*str < '0' || *str > '9') { - return 0; + return false; } leading_zero = (*str == '0'); m = 1; @@ -740,30 +736,30 @@ static int _php_filter_validate_ipv4(char *str, size_t str_len, int *ip) /* {{{ while (str < end && (*str >= '0' && *str <= '9')) { num = num * 10 + ((*(str++)) - '0'); if (num > 255 || ++m > 3) { - return 0; + return false; } } /* don't allow a leading 0; that introduces octal numbers, * which we don't support */ if (leading_zero && (num != 0 || m > 1)) - return 0; + return false; ip[n++] = num; if (n == 4) { return str == end; } else if (str >= end || *(str++) != '.') { - return 0; + return false; } } - return 0; + return false; } /* }}} */ -static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]) /* {{{ */ +static bool _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]) /* {{{ */ { int compressed_pos = -1; int blocks = 0; int num, n, i; - char *ipv4; + const char *ipv4; const char *end; int ip4elm[4]; const char *s = str; @@ -802,11 +798,11 @@ static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]) if (*str == ':') { if (++str >= end) { /* cannot end in : without previous : */ - return 0; + return false; } if (*str == ':') { if (compressed_pos >= 0) { - return 0; + return false; } if (ip && blocks < 8) { ip[blocks] = -1; @@ -814,13 +810,13 @@ static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]) compressed_pos = blocks++; /* :: means 1 or more 16-bit 0 blocks */ if (++str == end) { if (blocks > 8) { - return 0; + return false; } goto fixup_ip; } } else if ((str - 1) == s) { /* don't allow leading : without another : following */ - return 0; + return false; } } num = n = 0; @@ -841,10 +837,10 @@ static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8]) ip[blocks] = num; } if (n < 1 || n > 4) { - return 0; + return false; } if (++blocks > 8) - return 0; + return false; } fixup_ip: @@ -1010,7 +1006,7 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } } else if (mode == FORMAT_IPV6) { - if (_php_filter_validate_ipv6(Z_STRVAL_P(value), Z_STRLEN_P(value), ip) < 1) { + if (!_php_filter_validate_ipv6(Z_STRVAL_P(value), Z_STRLEN_P(value), ip)) { RETURN_VALIDATION_FAILED } @@ -1035,9 +1031,9 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { - char *input = Z_STRVAL_P(value); + const char *input = Z_STRVAL_P(value); size_t input_len = Z_STRLEN_P(value); - int tokens, length, i, offset, exp_separator_set; + int tokens, length, exp_separator_set; size_t exp_separator_len; char separator; char *exp_separator; @@ -1080,14 +1076,14 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ * a hexadecimal number followed by a separator character. (With the * exception of the last token which does not have the separator.) */ - for (i = 0; i < tokens; i++) { - offset = i * (length + 1); + for (int i = 0; i < tokens; i++) { + int offset = i * (length + 1); if (i < tokens - 1 && input[offset + length] != separator) { /* The current token did not end with e.g. a "." */ RETURN_VALIDATION_FAILED } - if (php_filter_parse_hex(input + offset, length, &ret) < 0) { + if (!php_filter_parse_hex(input + offset, length, &ret)) { /* The current token is no valid hexadecimal digit */ RETURN_VALIDATION_FAILED } diff --git a/ext/filter/php_filter.h b/ext/filter/php_filter.h index 4587a375e43b8..f782907898fca 100644 --- a/ext/filter/php_filter.h +++ b/ext/filter/php_filter.h @@ -42,9 +42,6 @@ ZEND_BEGIN_MODULE_GLOBALS(filter) zval cookie_array; zval env_array; zval server_array; -#if 0 - zval session_array; -#endif zend_long default_filter; zend_long default_filter_flags; ZEND_END_MODULE_GLOBALS(filter) diff --git a/ext/filter/sanitizing_filters.c b/ext/filter/sanitizing_filters.c index 647d559c1df56..7f8b4948d5818 100644 --- a/ext/filter/sanitizing_filters.c +++ b/ext/filter/sanitizing_filters.c @@ -60,12 +60,12 @@ static const unsigned char hexchars[] = "0123456789ABCDEF"; #define DEFAULT_URL_ENCODE LOWALPHA HIALPHA DIGIT "-._" -static void php_filter_encode_url(zval *value, const unsigned char* chars, const int char_len, int high, int low, int encode_nul) +static void php_filter_encode_url(zval *value, const unsigned char* chars, const int char_len) { unsigned char *p; unsigned char tmp[256]; - unsigned char *s = (unsigned char *)chars; - unsigned char *e = s + char_len; + const unsigned char *s = chars; + const unsigned char *e = s + char_len; zend_string *str; memset(tmp, 1, sizeof(tmp)-1); @@ -75,8 +75,8 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const } str = zend_string_safe_alloc(Z_STRLEN_P(value), 3, 0, 0); - p = (unsigned char *) ZSTR_VAL(str); - s = (unsigned char *) Z_STRVAL_P(value); + p = (unsigned char*)ZSTR_VAL(str); + s = (const unsigned char*)Z_STRVAL_P(value); e = s + Z_STRLEN_P(value); while (s < e) { @@ -90,15 +90,14 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const s++; } *p = '\0'; - ZSTR_LEN(str) = p - (unsigned char *)ZSTR_VAL(str); + ZSTR_LEN(str) = p - (const unsigned char *)ZSTR_VAL(str); zval_ptr_dtor(value); ZVAL_NEW_STR(value, str); } static void php_filter_strip(zval *value, zend_long flags) { - unsigned char *str; - size_t i; + const unsigned char *str; size_t c; zend_string *buf; @@ -107,10 +106,10 @@ static void php_filter_strip(zval *value, zend_long flags) return; } - str = (unsigned char *)Z_STRVAL_P(value); + str = (const unsigned char *)Z_STRVAL_P(value); buf = zend_string_alloc(Z_STRLEN_P(value), 0); c = 0; - for (i = 0; i < Z_STRLEN_P(value); i++) { + for (size_t i = 0; i < Z_STRLEN_P(value); i++) { if ((str[i] >= 127) && (flags & FILTER_FLAG_STRIP_HIGH)) { } else if ((str[i] < 32) && (flags & FILTER_FLAG_STRIP_LOW)) { } else if ((str[i] == '`') && (flags & FILTER_FLAG_STRIP_BACKTICK)) { @@ -143,9 +142,9 @@ static void filter_map_update(filter_map *map, int flag, const unsigned char *al } } -static void filter_map_apply(zval *value, filter_map *map) +static void filter_map_apply(zval *value, const filter_map *map) { - unsigned char *str; + const unsigned char *str; size_t i, c; zend_string *buf; @@ -216,7 +215,7 @@ void php_filter_encoded(PHP_INPUT_FILTER_PARAM_DECL) /* apply strip_high and strip_low filters */ php_filter_strip(value, flags); /* urlencode */ - php_filter_encode_url(value, (unsigned char *)DEFAULT_URL_ENCODE, sizeof(DEFAULT_URL_ENCODE)-1, flags & FILTER_FLAG_ENCODE_HIGH, flags & FILTER_FLAG_ENCODE_LOW, 1); + php_filter_encode_url(value, (unsigned char *)DEFAULT_URL_ENCODE, sizeof(DEFAULT_URL_ENCODE)-1); } /* }}} */