Skip to content

Commit 7cc4708

Browse files
committed
ext/filter: Use zend_string* instead of a char* + size_t pair
1 parent 0e682ad commit 7cc4708

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

ext/filter/logical_filters.c

+10-15
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,16 @@ void php_filter_validate_regexp(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
504504
}
505505
}
506506

507-
static int _php_filter_validate_domain(const char *domain, size_t len, zend_long flags) /* {{{ */
507+
static int php_filter_validate_domain_ex(const zend_string *domain, zend_long flags) /* {{{ */
508508
{
509509
const char *e, *s, *t;
510510
size_t l;
511511
int hostname = flags & FILTER_FLAG_HOSTNAME;
512512
unsigned char i = 1;
513513

514-
s = domain;
515-
l = len;
516-
e = domain + l;
514+
s = ZSTR_VAL(domain);
515+
l = ZSTR_LEN(domain);
516+
e = s + l;
517517
t = e - 1;
518518

519519
/* Ignore trailing dot */
@@ -558,7 +558,7 @@ static int _php_filter_validate_domain(const char *domain, size_t len, zend_long
558558

559559
void php_filter_validate_domain(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
560560
{
561-
if (!_php_filter_validate_domain(Z_STRVAL_P(value), Z_STRLEN_P(value), flags)) {
561+
if (!php_filter_validate_domain_ex(Z_STR_P(value), flags)) {
562562
RETURN_VALIDATION_FAILED
563563
}
564564
}
@@ -580,12 +580,12 @@ static int is_userinfo_valid(const zend_string *str)
580580
return 1;
581581
}
582582

583-
static bool php_filter_is_valid_ipv6_hostname(const char *s, size_t l)
583+
static bool php_filter_is_valid_ipv6_hostname(const zend_string *s)
584584
{
585-
const char *e = s + l;
585+
const char *e = ZSTR_VAL(s) + ZSTR_LEN(s);
586586
const char *t = e - 1;
587587

588-
return *s == '[' && *t == ']' && _php_filter_validate_ipv6(s + 1, l - 2, NULL);
588+
return *ZSTR_VAL(s) == '[' && *t == ']' && _php_filter_validate_ipv6(ZSTR_VAL(s) + 1, ZSTR_LEN(s) - 2, NULL);
589589
}
590590

591591
void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
@@ -608,22 +608,17 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
608608

609609
if (url->scheme != NULL &&
610610
(zend_string_equals_literal_ci(url->scheme, "http") || zend_string_equals_literal_ci(url->scheme, "https"))) {
611-
const char *s;
612-
size_t l;
613611

614612
if (url->host == NULL) {
615613
goto bad_url;
616614
}
617615

618-
s = ZSTR_VAL(url->host);
619-
l = ZSTR_LEN(url->host);
620-
621616
if (
622617
/* An IPv6 enclosed by square brackets is a valid hostname.*/
623-
!php_filter_is_valid_ipv6_hostname(s, l) &&
618+
!php_filter_is_valid_ipv6_hostname(url->host) &&
624619
/* Validate domain.
625620
* This includes a loose check for an IPv4 address. */
626-
!_php_filter_validate_domain(ZSTR_VAL(url->host), l, FILTER_FLAG_HOSTNAME)
621+
!php_filter_validate_domain_ex(url->host, FILTER_FLAG_HOSTNAME)
627622
) {
628623
php_url_free(url);
629624
RETURN_VALIDATION_FAILED

0 commit comments

Comments
 (0)