Skip to content

Commit 3fb334c

Browse files
committed
php_pgsql_convert_match() use zend_string for main string
1 parent 90dc920 commit 3fb334c

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

ext/pgsql/pgsql.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,7 +4456,7 @@ static php_pgsql_data_type php_pgsql_get_data_type(const zend_string *type_name)
44564456
/* {{{ php_pgsql_convert_match
44574457
* test field value with regular expression specified.
44584458
*/
4459-
static int php_pgsql_convert_match(const char *str, size_t str_len, const char *regex , size_t regex_len, int icase)
4459+
static int php_pgsql_convert_match(const zend_string *str, const char *regex , size_t regex_len, int icase)
44604460
{
44614461
pcre2_code *re;
44624462
PCRE2_SIZE err_offset;
@@ -4466,10 +4466,10 @@ static int php_pgsql_convert_match(const char *str, size_t str_len, const char *
44664466
pcre2_match_data *match_data;
44674467

44684468
/* Check invalid chars for POSIX regex */
4469-
for (i = 0; i < str_len; i++) {
4470-
if (str[i] == '\n' ||
4471-
str[i] == '\r' ||
4472-
str[i] == '\0' ) {
4469+
for (i = 0; i < ZSTR_LEN(str); i++) {
4470+
if (ZSTR_VAL(str)[i] == '\n' ||
4471+
ZSTR_VAL(str)[i] == '\r' ||
4472+
ZSTR_VAL(str)[i] == '\0' ) {
44734473
return FAILURE;
44744474
}
44754475
}
@@ -4492,7 +4492,7 @@ static int php_pgsql_convert_match(const char *str, size_t str_len, const char *
44924492
php_error_docref(NULL, E_WARNING, "Cannot allocate match data");
44934493
return FAILURE;
44944494
}
4495-
res = pcre2_match(re, (PCRE2_SPTR)str, str_len, 0, 0, match_data, php_pcre_mctx());
4495+
res = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(str), ZSTR_LEN(str), 0, 0, match_data, php_pcre_mctx());
44964496
php_pcre_free_match_data(match_data);
44974497
pcre2_code_free(re);
44984498

@@ -4692,7 +4692,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
46924692
else {
46934693
/* FIXME: better regex must be used */
46944694
#define REGEX0 "^([+-]{0,1}[0-9]+)$"
4695-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE) {
4695+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE) {
46964696
err = 1;
46974697
}
46984698
else {
@@ -4737,8 +4737,8 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
47374737
#define REGEX0 "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"
47384738
#define REGEX1 "^[+-]{0,1}(inf)(inity){0,1}$"
47394739
/* better regex? */
4740-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE) {
4741-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX1, sizeof(REGEX1)-1, 1) == FAILURE) {
4740+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE) {
4741+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX1, sizeof(REGEX1)-1, 1) == FAILURE) {
47424742
err = 1;
47434743
} else {
47444744
ZVAL_STRING(&new_val, Z_STRVAL_P(val));
@@ -4846,7 +4846,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
48464846
}
48474847
else {
48484848
/* better regex? */
4849-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), "^[0-9]+$", sizeof("^[0-9]+$")-1, 0) == FAILURE) {
4849+
if (php_pgsql_convert_match(Z_STR_P(val), "^[0-9]+$", sizeof("^[0-9]+$")-1, 0) == FAILURE) {
48504850
err = 1;
48514851
}
48524852
else {
@@ -4891,8 +4891,8 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
48914891
/* The inet type holds an IPv4 or IPv6 host address, and optionally its subnet, all in one field. See more in the doc.
48924892
The regex might still be not perfect, but catches the most of IP variants. We might decide to remove the regex
48934893
at all though and let the server side to handle it.*/
4894-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE
4895-
&& php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX1, sizeof(REGEX1)-1, 0) == FAILURE) {
4894+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 0) == FAILURE
4895+
&& php_pgsql_convert_match(Z_STR_P(val), REGEX1, sizeof(REGEX1)-1, 0) == FAILURE) {
48964896
err = 1;
48974897
}
48984898
else {
@@ -4929,7 +4929,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
49294929
} else {
49304930
#define REGEX0 "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})(([ \\t]+|T)(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}(\\.[0-9]+){0,1}([ \\t]*([+-][0-9]{1,4}(:[0-9]{1,2}){0,1}|[-a-zA-Z_/+]{1,50})){0,1})){0,1}$"
49314931
/* better regex? */
4932-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
4932+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
49334933
err = 1;
49344934
} else {
49354935
ZVAL_STRING(&new_val, Z_STRVAL_P(val));
@@ -4961,7 +4961,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
49614961
else {
49624962
#define REGEX0 "^([0-9]{4}[/-][0-9]{1,2}[/-][0-9]{1,2})$"
49634963
/* FIXME: better regex must be used */
4964-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
4964+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
49654965
err = 1;
49664966
}
49674967
else {
@@ -4994,7 +4994,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
49944994
else {
49954995
#define REGEX0 "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}){0,1}$"
49964996
/* FIXME: better regex must be used */
4997-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
4997+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
49984998
err = 1;
49994999
}
50005000
else {
@@ -5073,7 +5073,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
50735073
")?))" \
50745074
"([ \\t]+ago)?$"
50755075

5076-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
5076+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
50775077
err = 1;
50785078
}
50795079
else {
@@ -5147,7 +5147,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
51475147
}
51485148
else {
51495149
#define REGEX0 "^([0-9a-f]{2,2}:){5,5}[0-9a-f]{2,2}$"
5150-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
5150+
if (php_pgsql_convert_match(Z_STR_P(val), REGEX0, sizeof(REGEX0)-1, 1) == FAILURE) {
51515151
err = 1;
51525152
}
51535153
else {

0 commit comments

Comments
 (0)