Skip to content

Commit 965178a

Browse files
Drop _IS_ERROR hack
1 parent 49ed12e commit 965178a

File tree

6 files changed

+73
-54
lines changed

6 files changed

+73
-54
lines changed

ext/filter/callback_filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "php_filter.h"
1818

19-
void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
19+
zend_result php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
2020
{
2121
zval retval;
2222
int status;
@@ -25,7 +25,7 @@ void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
2525
zend_type_error("%s(): Option must be a valid callback", get_active_function_name());
2626
zval_ptr_dtor(value);
2727
ZVAL_NULL(value);
28-
return;
28+
return SUCCESS;
2929
}
3030

3131
status = call_user_function(NULL, NULL, option_array, &retval, 1, value);
@@ -37,4 +37,5 @@ void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL)
3737
zval_ptr_dtor(value);
3838
ZVAL_NULL(value);
3939
}
40+
return SUCCESS;
4041
}

ext/filter/filter.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ZEND_DECLARE_MODULE_GLOBALS(filter)
3434
typedef struct filter_list_entry {
3535
const char *name;
3636
int id;
37-
void (*function)(PHP_INPUT_FILTER_PARAM_DECL);
37+
zend_result (*function)(PHP_INPUT_FILTER_PARAM_DECL);
3838
} filter_list_entry;
3939

4040
/* {{{ filter_list */
@@ -284,12 +284,11 @@ static void php_zval_filter(zval *value, zend_long filter, zend_long flags, zval
284284
copy_for_throwing = zend_string_copy(Z_STR_P(value));
285285
}
286286

287-
filter_func.function(value, flags, options, charset);
287+
zend_result result = filter_func.function(value, flags, options, charset);
288288

289289
if (flags & FILTER_THROW_ON_FAILURE) {
290290
ZEND_ASSERT(copy_for_throwing != NULL);
291-
if (Z_ISERROR_P(value)) {
292-
ZVAL_NULL(value);
291+
if (result == FAILURE) {
293292
zend_throw_exception_ex(
294293
php_filter_failed_exception_ce,
295294
0,

ext/filter/filter_private.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,24 @@
9696

9797

9898
/* When using FILTER_THROW_ON_FAILURE, we can't actually throw the error here
99-
* because we don't have access to the name of the filter. Use ZVAL_ERROR()
100-
* so that we can easily identify places where we want to throw. */
99+
* because we don't have access to the name of the filter. Returning FAILURE
100+
* from the filter handler indicates that validation failed *and* an exception
101+
* should thus be thrown. */
101102
#define RETURN_VALIDATION_FAILED \
102103
if (EG(exception)) { \
103-
return; \
104+
return SUCCESS; \
104105
} else if (flags & FILTER_THROW_ON_FAILURE) { \
105106
zval_ptr_dtor(value); \
106-
ZVAL_ERROR(value); \
107+
ZVAL_NULL(value); \
108+
return FAILURE; \
107109
} else if (flags & FILTER_NULL_ON_FAILURE) { \
108110
zval_ptr_dtor(value); \
109111
ZVAL_NULL(value); \
110112
} else { \
111113
zval_ptr_dtor(value); \
112114
ZVAL_FALSE(value); \
113115
} \
114-
return; \
116+
return SUCCESS; \
115117

116118
#define PHP_FILTER_TRIM_DEFAULT(p, len) PHP_FILTER_TRIM_DEFAULT_EX(p, len, 1);
117119

ext/filter/logical_filters.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static bool php_filter_parse_hex(const char *str, size_t str_len, zend_long *ret
195195
}
196196
/* }}} */
197197

198-
void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
198+
zend_result php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
199199
{
200200
zval *option_val;
201201
zend_long min_range, max_range, option_flags;
@@ -266,12 +266,12 @@ void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
266266
} else {
267267
zval_ptr_dtor(value);
268268
ZVAL_LONG(value, ctx_value);
269-
return;
270269
}
270+
return SUCCESS;
271271
}
272272
/* }}} */
273273

274-
void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
274+
zend_result php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
275275
{
276276
const char *str = Z_STRVAL_P(value);
277277
size_t len = Z_STRLEN_P(value);
@@ -337,10 +337,11 @@ void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
337337
zval_ptr_dtor(value);
338338
ZVAL_BOOL(value, ret);
339339
}
340+
return SUCCESS;
340341
}
341342
/* }}} */
342343

343-
void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
344+
zend_result php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
344345
{
345346
size_t len;
346347
const char *str, *end;
@@ -467,10 +468,11 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
467468
RETURN_VALIDATION_FAILED
468469
}
469470
efree(num);
471+
return SUCCESS;
470472
}
471473
/* }}} */
472474

473-
void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
475+
zend_result php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
474476
{
475477
zval *option_val;
476478
zend_string *regexp;
@@ -503,6 +505,7 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
503505
if (rc < 0) {
504506
RETURN_VALIDATION_FAILED
505507
}
508+
return SUCCESS;
506509
}
507510

508511
static bool php_filter_validate_domain_ex(const zend_string *domain, zend_long flags) /* {{{ */
@@ -557,11 +560,12 @@ static bool php_filter_validate_domain_ex(const zend_string *domain, zend_long f
557560
}
558561
/* }}} */
559562

560-
void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
563+
zend_result php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
561564
{
562565
if (!php_filter_validate_domain_ex(Z_STR_P(value), flags)) {
563566
RETURN_VALIDATION_FAILED
564567
}
568+
return SUCCESS;
565569
}
566570
/* }}} */
567571

@@ -589,7 +593,7 @@ static bool php_filter_is_valid_ipv6_hostname(const zend_string *s)
589593
return *ZSTR_VAL(s) == '[' && *t == ']' && _php_filter_validate_ipv6(ZSTR_VAL(s) + 1, ZSTR_LEN(s) - 2, NULL);
590594
}
591595

592-
void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
596+
zend_result php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
593597
{
594598
php_url *url;
595599
size_t old_len = Z_STRLEN_P(value);
@@ -646,10 +650,11 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
646650
}
647651

648652
php_url_free(url);
653+
return SUCCESS;
649654
}
650655
/* }}} */
651656

652-
void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
657+
zend_result php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
653658
{
654659
/*
655660
* The regex below is based on a regex by Michael Rushton.
@@ -715,6 +720,7 @@ void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
715720
if (rc < 0) {
716721
RETURN_VALIDATION_FAILED
717722
}
723+
return SUCCESS;
718724

719725
}
720726
/* }}} */
@@ -975,7 +981,7 @@ static bool ipv6_get_status_flags(const int ip[8], bool *global, bool *reserved,
975981
* to throw out reserved ranges; multicast ranges... etc. If both allow_ipv4
976982
* and allow_ipv6 flags flag are used, then the first dot or colon determine
977983
* the format */
978-
void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
984+
zend_result php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
979985
{
980986
int ip[8];
981987
int mode;
@@ -1003,7 +1009,7 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10031009
}
10041010

10051011
if (!ipv4_get_status_flags(ip, &flag_global, &flag_reserved, &flag_private)) {
1006-
return; /* no special block */
1012+
return SUCCESS; /* no special block */
10071013
}
10081014
}
10091015
else if (mode == FORMAT_IPV6) {
@@ -1012,7 +1018,7 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10121018
}
10131019

10141020
if (!ipv6_get_status_flags(ip, &flag_global, &flag_reserved, &flag_private)) {
1015-
return; /* no special block */
1021+
return SUCCESS; /* no special block */
10161022
}
10171023
}
10181024

@@ -1027,10 +1033,11 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10271033
if ((flags & FILTER_FLAG_NO_RES_RANGE) && flag_reserved == true) {
10281034
RETURN_VALIDATION_FAILED
10291035
}
1036+
return SUCCESS;
10301037
}
10311038
/* }}} */
10321039

1033-
void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
1040+
zend_result php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10341041
{
10351042
const char *input = Z_STRVAL_P(value);
10361043
size_t input_len = Z_STRLEN_P(value);
@@ -1089,5 +1096,6 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10891096
RETURN_VALIDATION_FAILED
10901097
}
10911098
}
1099+
return SUCCESS;
10921100
}
10931101
/* }}} */

ext/filter/php_filter.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,27 @@ ZEND_TSRMLS_CACHE_EXTERN()
5353
#define IF_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(filter, v)
5454

5555
#define PHP_INPUT_FILTER_PARAM_DECL zval *value, zend_long flags, zval *option_array, char *charset
56-
void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL);
57-
void php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL);
58-
void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL);
59-
void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL);
60-
void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL);
61-
void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL);
62-
void php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL);
63-
void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL);
64-
void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL);
56+
zend_result php_filter_int(PHP_INPUT_FILTER_PARAM_DECL);
57+
zend_result php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL);
58+
zend_result php_filter_float(PHP_INPUT_FILTER_PARAM_DECL);
59+
zend_result php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL);
60+
zend_result php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL);
61+
zend_result php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL);
62+
zend_result php_filter_validate_email(PHP_INPUT_FILTER_PARAM_DECL);
63+
zend_result php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL);
64+
zend_result php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL);
6565

66-
void php_filter_string(PHP_INPUT_FILTER_PARAM_DECL);
67-
void php_filter_encoded(PHP_INPUT_FILTER_PARAM_DECL);
68-
void php_filter_special_chars(PHP_INPUT_FILTER_PARAM_DECL);
69-
void php_filter_full_special_chars(PHP_INPUT_FILTER_PARAM_DECL);
70-
void php_filter_unsafe_raw(PHP_INPUT_FILTER_PARAM_DECL);
71-
void php_filter_email(PHP_INPUT_FILTER_PARAM_DECL);
72-
void php_filter_url(PHP_INPUT_FILTER_PARAM_DECL);
73-
void php_filter_number_int(PHP_INPUT_FILTER_PARAM_DECL);
74-
void php_filter_number_float(PHP_INPUT_FILTER_PARAM_DECL);
75-
void php_filter_add_slashes(PHP_INPUT_FILTER_PARAM_DECL);
66+
zend_result php_filter_string(PHP_INPUT_FILTER_PARAM_DECL);
67+
zend_result php_filter_encoded(PHP_INPUT_FILTER_PARAM_DECL);
68+
zend_result php_filter_special_chars(PHP_INPUT_FILTER_PARAM_DECL);
69+
zend_result php_filter_full_special_chars(PHP_INPUT_FILTER_PARAM_DECL);
70+
zend_result php_filter_unsafe_raw(PHP_INPUT_FILTER_PARAM_DECL);
71+
zend_result php_filter_email(PHP_INPUT_FILTER_PARAM_DECL);
72+
zend_result php_filter_url(PHP_INPUT_FILTER_PARAM_DECL);
73+
zend_result php_filter_number_int(PHP_INPUT_FILTER_PARAM_DECL);
74+
zend_result php_filter_number_float(PHP_INPUT_FILTER_PARAM_DECL);
75+
zend_result php_filter_add_slashes(PHP_INPUT_FILTER_PARAM_DECL);
7676

77-
void php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL);
77+
zend_result php_filter_callback(PHP_INPUT_FILTER_PARAM_DECL);
7878

7979
#endif /* FILTER_H */

0 commit comments

Comments
 (0)