From 48eb42c476a4be05fc38b3fa705eef39851a4ea8 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:22:49 +0000 Subject: [PATCH 1/7] Use zend_string_equals() API instead of strcmp() in main.c --- main/main.c | 60 +++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/main/main.c b/main/main.c index fabff08bc504..881ae6e642d1 100644 --- a/main/main.c +++ b/main/main.c @@ -99,130 +99,131 @@ PHPAPI size_t core_globals_offset; /* {{{ PHP_INI_MH */ static PHP_INI_MH(OnSetFacility) { - const char *facility = ZSTR_VAL(new_value); + const zend_string *facility = new_value; #ifdef LOG_AUTH - if (!strcmp(facility, "LOG_AUTH") || !strcmp(facility, "auth") || !strcmp(facility, "security")) { + if (zend_string_equals_literal(facility, "LOG_AUTH") || zend_string_equals_literal(facility, "auth") + || zend_string_equals_literal(facility, "security")) { PG(syslog_facility) = LOG_AUTH; return SUCCESS; } #endif #ifdef LOG_AUTHPRIV - if (!strcmp(facility, "LOG_AUTHPRIV") || !strcmp(facility, "authpriv")) { + if (zend_string_equals_literal(facility, "LOG_AUTHPRIV") || zend_string_equals_literal(facility, "authpriv")) { PG(syslog_facility) = LOG_AUTHPRIV; return SUCCESS; } #endif #ifdef LOG_CRON - if (!strcmp(facility, "LOG_CRON") || !strcmp(facility, "cron")) { + if (zend_string_equals_literal(facility, "LOG_CRON") || zend_string_equals_literal(facility, "cron")) { PG(syslog_facility) = LOG_CRON; return SUCCESS; } #endif #ifdef LOG_DAEMON - if (!strcmp(facility, "LOG_DAEMON") || !strcmp(facility, "daemon")) { + if (zend_string_equals_literal(facility, "LOG_DAEMON") || zend_string_equals_literal(facility, "daemon")) { PG(syslog_facility) = LOG_DAEMON; return SUCCESS; } #endif #ifdef LOG_FTP - if (!strcmp(facility, "LOG_FTP") || !strcmp(facility, "ftp")) { + if (zend_string_equals_literal(facility, "LOG_FTP") || zend_string_equals_literal(facility, "ftp")) { PG(syslog_facility) = LOG_FTP; return SUCCESS; } #endif #ifdef LOG_KERN - if (!strcmp(facility, "LOG_KERN") || !strcmp(facility, "kern")) { + if (zend_string_equals_literal(facility, "LOG_KERN") || zend_string_equals_literal(facility, "kern")) { PG(syslog_facility) = LOG_KERN; return SUCCESS; } #endif #ifdef LOG_LPR - if (!strcmp(facility, "LOG_LPR") || !strcmp(facility, "lpr")) { + if (zend_string_equals_literal(facility, "LOG_LPR") || zend_string_equals_literal(facility, "lpr")) { PG(syslog_facility) = LOG_LPR; return SUCCESS; } #endif #ifdef LOG_MAIL - if (!strcmp(facility, "LOG_MAIL") || !strcmp(facility, "mail")) { + if (zend_string_equals_literal(facility, "LOG_MAIL") || zend_string_equals_literal(facility, "mail")) { PG(syslog_facility) = LOG_MAIL; return SUCCESS; } #endif #ifdef LOG_INTERNAL_MARK - if (!strcmp(facility, "LOG_INTERNAL_MARK") || !strcmp(facility, "mark")) { + if (zend_string_equals_literal(facility, "LOG_INTERNAL_MARK") || zend_string_equals_literal(facility, "mark")) { PG(syslog_facility) = LOG_INTERNAL_MARK; return SUCCESS; } #endif #ifdef LOG_NEWS - if (!strcmp(facility, "LOG_NEWS") || !strcmp(facility, "news")) { + if (zend_string_equals_literal(facility, "LOG_NEWS") || zend_string_equals_literal(facility, "news")) { PG(syslog_facility) = LOG_NEWS; return SUCCESS; } #endif #ifdef LOG_SYSLOG - if (!strcmp(facility, "LOG_SYSLOG") || !strcmp(facility, "syslog")) { + if (zend_string_equals_literal(facility, "LOG_SYSLOG") || zend_string_equals_literal(facility, "syslog")) { PG(syslog_facility) = LOG_SYSLOG; return SUCCESS; } #endif #ifdef LOG_USER - if (!strcmp(facility, "LOG_USER") || !strcmp(facility, "user")) { + if (zend_string_equals_literal(facility, "LOG_USER") || zend_string_equals_literal(facility, "user")) { PG(syslog_facility) = LOG_USER; return SUCCESS; } #endif #ifdef LOG_UUCP - if (!strcmp(facility, "LOG_UUCP") || !strcmp(facility, "uucp")) { + if (zend_string_equals_literal(facility, "LOG_UUCP") || zend_string_equals_literal(facility, "uucp")) { PG(syslog_facility) = LOG_UUCP; return SUCCESS; } #endif #ifdef LOG_LOCAL0 - if (!strcmp(facility, "LOG_LOCAL0") || !strcmp(facility, "local0")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL0") || zend_string_equals_literal(facility, "local0")) { PG(syslog_facility) = LOG_LOCAL0; return SUCCESS; } #endif #ifdef LOG_LOCAL1 - if (!strcmp(facility, "LOG_LOCAL1") || !strcmp(facility, "local1")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL1") || zend_string_equals_literal(facility, "local1")) { PG(syslog_facility) = LOG_LOCAL1; return SUCCESS; } #endif #ifdef LOG_LOCAL2 - if (!strcmp(facility, "LOG_LOCAL2") || !strcmp(facility, "local2")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL2") || zend_string_equals_literal(facility, "local2")) { PG(syslog_facility) = LOG_LOCAL2; return SUCCESS; } #endif #ifdef LOG_LOCAL3 - if (!strcmp(facility, "LOG_LOCAL3") || !strcmp(facility, "local3")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL3") || zend_string_equals_literal(facility, "local3")) { PG(syslog_facility) = LOG_LOCAL3; return SUCCESS; } #endif #ifdef LOG_LOCAL4 - if (!strcmp(facility, "LOG_LOCAL4") || !strcmp(facility, "local4")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL4") || zend_string_equals_literal(facility, "local4")) { PG(syslog_facility) = LOG_LOCAL4; return SUCCESS; } #endif #ifdef LOG_LOCAL5 - if (!strcmp(facility, "LOG_LOCAL5") || !strcmp(facility, "local5")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL5") || zend_string_equals_literal(facility, "local5")) { PG(syslog_facility) = LOG_LOCAL5; return SUCCESS; } #endif #ifdef LOG_LOCAL6 - if (!strcmp(facility, "LOG_LOCAL6") || !strcmp(facility, "local6")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL6") || zend_string_equals_literal(facility, "local6")) { PG(syslog_facility) = LOG_LOCAL6; return SUCCESS; } #endif #ifdef LOG_LOCAL7 - if (!strcmp(facility, "LOG_LOCAL7") || !strcmp(facility, "local7")) { + if (zend_string_equals_literal(facility, "LOG_LOCAL7") || zend_string_equals_literal(facility, "local7")) { PG(syslog_facility) = LOG_LOCAL7; return SUCCESS; } @@ -278,21 +279,21 @@ static PHP_INI_MH(OnChangeMemoryLimit) /* {{{ PHP_INI_MH */ static PHP_INI_MH(OnSetLogFilter) { - const char *filter = ZSTR_VAL(new_value); + const zend_string *filter = new_value; - if (!strcmp(filter, "all")) { + if (zend_string_equals_literal(filter, "all")) { PG(syslog_filter) = PHP_SYSLOG_FILTER_ALL; return SUCCESS; } - if (!strcmp(filter, "no-ctrl")) { + if (zend_string_equals_literal(filter, "no-ctrl")) { PG(syslog_filter) = PHP_SYSLOG_FILTER_NO_CTRL; return SUCCESS; } - if (!strcmp(filter, "ascii")) { + if (zend_string_equals_literal(filter, "ascii")) { PG(syslog_filter) = PHP_SYSLOG_FILTER_ASCII; return SUCCESS; } - if (!strcmp(filter, "raw")) { + if (zend_string_equals_literal(filter, "raw")) { PG(syslog_filter) = PHP_SYSLOG_FILTER_RAW; return SUCCESS; } @@ -585,7 +586,8 @@ static PHP_INI_MH(OnUpdateOutputEncoding) static PHP_INI_MH(OnUpdateErrorLog) { /* Only do the safemode/open_basedir check at runtime */ - if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && new_value && strcmp(ZSTR_VAL(new_value), "syslog")) { + if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && + new_value && zend_string_equals_literal(new_value, "syslog")) { if (PG(open_basedir) && php_check_open_basedir(ZSTR_VAL(new_value))) { return FAILURE; } @@ -2465,7 +2467,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file) * otherwise it will get opened and added to the included_files list in zend_execute_scripts */ if (primary_file->filename && - strcmp("Standard input code", ZSTR_VAL(primary_file->filename)) && + !zend_string_equals_literal(primary_file->filename, "Standard input code") && primary_file->opened_path == NULL && primary_file->type != ZEND_HANDLE_FILENAME ) { From f5e626aea0e3cfada3c0bd976e3caed6e76713b0 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:23:02 +0000 Subject: [PATCH 2/7] Use zend_string_equals() API instead of strcmp() in SOAP extension --- ext/soap/php_http.c | 2 +- ext/soap/soap.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index b14c8cc1a10a..9119fee9a79f 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -491,7 +491,7 @@ int make_http_soap_request(zval *this_ptr, (((use_ssl && orig->scheme != NULL && zend_string_equals_literal(orig->scheme, "https")) || (!use_ssl && orig->scheme == NULL) || (!use_ssl && !zend_string_equals_literal(orig->scheme, "https"))) && - strcmp(ZSTR_VAL(orig->host), ZSTR_VAL(phpurl->host)) == 0 && + zend_string_equals(orig->host, phpurl->host) && orig->port == phpurl->port))) { } else { php_stream_close(stream); diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 49815082a83b..b1423bc60a42 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1275,9 +1275,9 @@ PHP_METHOD(SoapServer, handle) (encoding = zend_hash_str_find(Z_ARRVAL_P(server_vars), "HTTP_CONTENT_ENCODING", sizeof("HTTP_CONTENT_ENCODING")-1)) != NULL && Z_TYPE_P(encoding) == IS_STRING) { - if (strcmp(Z_STRVAL_P(encoding),"gzip") == 0 - || strcmp(Z_STRVAL_P(encoding),"x-gzip") == 0 - || strcmp(Z_STRVAL_P(encoding),"deflate") == 0 + if (zend_string_equals_literal(Z_STR_P(encoding), "gzip") + || zend_string_equals_literal(Z_STR_P(encoding), "x-gzip") + || zend_string_equals_literal(Z_STR_P(encoding), "deflate") ) { zval filter_params; From adcf1af91e734824fbd6a65a3b10e16b025d6d39 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:26:22 +0000 Subject: [PATCH 3/7] Use zend_string_equals() API instead of strcmp() in PGSQL extension And tiny drive by refactor at the same time for more usages --- ext/pgsql/pgsql.c | 100 +++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 5565d8fc85e5..7faa5af4fe8a 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -4385,88 +4385,87 @@ PHP_FUNCTION(pg_meta_data) /* }}} */ /* {{{ php_pgsql_get_data_type */ -static php_pgsql_data_type php_pgsql_get_data_type(const char *type_name, size_t len) +static php_pgsql_data_type php_pgsql_get_data_type(const zend_string *type_name) { - /* This is stupid way to do. I'll fix it when I decied how to support + /* This is stupid way to do. I'll fix it when I decide how to support user defined types. (Yasuo) */ - /* boolean */ - if (!strcmp(type_name, "bool")|| !strcmp(type_name, "boolean")) + if (zend_string_equals_literal(type_name, "bool")|| zend_string_equals_literal(type_name, "boolean")) return PG_BOOL; /* object id */ - if (!strcmp(type_name, "oid")) + if (zend_string_equals_literal(type_name, "oid")) return PG_OID; /* integer */ - if (!strcmp(type_name, "int2") || !strcmp(type_name, "smallint")) + if (zend_string_equals_literal(type_name, "int2") || zend_string_equals_literal(type_name, "smallint")) return PG_INT2; - if (!strcmp(type_name, "int4") || !strcmp(type_name, "integer")) + if (zend_string_equals_literal(type_name, "int4") || zend_string_equals_literal(type_name, "integer")) return PG_INT4; - if (!strcmp(type_name, "int8") || !strcmp(type_name, "bigint")) + if (zend_string_equals_literal(type_name, "int8") || zend_string_equals_literal(type_name, "bigint")) return PG_INT8; /* real and other */ - if (!strcmp(type_name, "float4") || !strcmp(type_name, "real")) + if (zend_string_equals_literal(type_name, "float4") || zend_string_equals_literal(type_name, "real")) return PG_FLOAT4; - if (!strcmp(type_name, "float8") || !strcmp(type_name, "double precision")) + if (zend_string_equals_literal(type_name, "float8") || zend_string_equals_literal(type_name, "double precision")) return PG_FLOAT8; - if (!strcmp(type_name, "numeric")) + if (zend_string_equals_literal(type_name, "numeric")) return PG_NUMERIC; - if (!strcmp(type_name, "money")) + if (zend_string_equals_literal(type_name, "money")) return PG_MONEY; /* character */ - if (!strcmp(type_name, "text")) + if (zend_string_equals_literal(type_name, "text")) return PG_TEXT; - if (!strcmp(type_name, "bpchar") || !strcmp(type_name, "character")) + if (zend_string_equals_literal(type_name, "bpchar") || zend_string_equals_literal(type_name, "character")) return PG_CHAR; - if (!strcmp(type_name, "varchar") || !strcmp(type_name, "character varying")) + if (zend_string_equals_literal(type_name, "varchar") || zend_string_equals_literal(type_name, "character varying")) return PG_VARCHAR; /* time and interval */ - if (!strcmp(type_name, "abstime")) + if (zend_string_equals_literal(type_name, "abstime")) return PG_UNIX_TIME; - if (!strcmp(type_name, "reltime")) + if (zend_string_equals_literal(type_name, "reltime")) return PG_UNIX_TIME_INTERVAL; - if (!strcmp(type_name, "tinterval")) + if (zend_string_equals_literal(type_name, "tinterval")) return PG_UNIX_TIME_INTERVAL; - if (!strcmp(type_name, "date")) + if (zend_string_equals_literal(type_name, "date")) return PG_DATE; - if (!strcmp(type_name, "time")) + if (zend_string_equals_literal(type_name, "time")) return PG_TIME; - if (!strcmp(type_name, "time with time zone") || !strcmp(type_name, "timetz")) + if (zend_string_equals_literal(type_name, "time with time zone") || zend_string_equals_literal(type_name, "timetz")) return PG_TIME_WITH_TIMEZONE; - if (!strcmp(type_name, "timestamp without time zone") || !strcmp(type_name, "timestamp")) + if (zend_string_equals_literal(type_name, "timestamp without time zone") || zend_string_equals_literal(type_name, "timestamp")) return PG_TIMESTAMP; - if (!strcmp(type_name, "timestamp with time zone") || !strcmp(type_name, "timestamptz")) + if (zend_string_equals_literal(type_name, "timestamp with time zone") || zend_string_equals_literal(type_name, "timestamptz")) return PG_TIMESTAMP_WITH_TIMEZONE; - if (!strcmp(type_name, "interval")) + if (zend_string_equals_literal(type_name, "interval")) return PG_INTERVAL; /* binary */ - if (!strcmp(type_name, "bytea")) + if (zend_string_equals_literal(type_name, "bytea")) return PG_BYTEA; /* network */ - if (!strcmp(type_name, "cidr")) + if (zend_string_equals_literal(type_name, "cidr")) return PG_CIDR; - if (!strcmp(type_name, "inet")) + if (zend_string_equals_literal(type_name, "inet")) return PG_INET; - if (!strcmp(type_name, "macaddr")) + if (zend_string_equals_literal(type_name, "macaddr")) return PG_MACADDR; /* bit */ - if (!strcmp(type_name, "bit")) + if (zend_string_equals_literal(type_name, "bit")) return PG_BIT; - if (!strcmp(type_name, "bit varying")) + if (zend_string_equals_literal(type_name, "bit varying")) return PG_VARBIT; /* geometric */ - if (!strcmp(type_name, "line")) + if (zend_string_equals_literal(type_name, "line")) return PG_LINE; - if (!strcmp(type_name, "lseg")) + if (zend_string_equals_literal(type_name, "lseg")) return PG_LSEG; - if (!strcmp(type_name, "box")) + if (zend_string_equals_literal(type_name, "box")) return PG_BOX; - if (!strcmp(type_name, "path")) + if (zend_string_equals_literal(type_name, "path")) return PG_PATH; - if (!strcmp(type_name, "point")) + if (zend_string_equals_literal(type_name, "point")) return PG_POINT; - if (!strcmp(type_name, "polygon")) + if (zend_string_equals_literal(type_name, "polygon")) return PG_POLYGON; - if (!strcmp(type_name, "circle")) + if (zend_string_equals_literal(type_name, "circle")) return PG_CIRCLE; return PG_UNKNOWN; @@ -4554,7 +4553,7 @@ static int php_pgsql_add_quotes(zval *src, bool should_free) /* Raise E_NOTICE to E_WARNING or Error? */ #define PGSQL_CONV_CHECK_IGNORE() \ - if (!err && Z_TYPE(new_val) == IS_STRING && !strcmp(Z_STRVAL(new_val), "NULL")) { \ + if (!err && Z_TYPE(new_val) == IS_STRING && zend_string_equals_literal(Z_STR(new_val), "NULL")) { \ /* if new_value is string "NULL" and field has default value, remove element to use default value */ \ if (!(opt & PGSQL_CONV_IGNORE_DEFAULT) && Z_TYPE_P(has_default) == IS_TRUE) { \ zval_ptr_dtor(&new_val); \ @@ -4636,7 +4635,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con /* enums need to be treated like strings */ data_type = PG_TEXT; } else { - data_type = php_pgsql_get_data_type(Z_STRVAL_P(type), Z_STRLEN_P(type)); + data_type = php_pgsql_get_data_type(Z_STR_P(type)); } /* TODO: Should E_NOTICE be converted to type error if PHP type cannot be converted to field type? */ @@ -4649,18 +4648,18 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con ZVAL_STRING(&new_val, "NULL"); } else { - if (!strcmp(Z_STRVAL_P(val), "t") || !strcmp(Z_STRVAL_P(val), "T") || - !strcmp(Z_STRVAL_P(val), "y") || !strcmp(Z_STRVAL_P(val), "Y") || - !strcmp(Z_STRVAL_P(val), "true") || !strcmp(Z_STRVAL_P(val), "True") || - !strcmp(Z_STRVAL_P(val), "yes") || !strcmp(Z_STRVAL_P(val), "Yes") || - !strcmp(Z_STRVAL_P(val), "1")) { + if (zend_string_equals_literal(Z_STR_P(val), "t") || zend_string_equals_literal(Z_STR_P(val), "T") || + zend_string_equals_literal(Z_STR_P(val), "y") || zend_string_equals_literal(Z_STR_P(val), "Y") || + zend_string_equals_literal(Z_STR_P(val), "true") || zend_string_equals_literal(Z_STR_P(val), "True") || + zend_string_equals_literal(Z_STR_P(val), "yes") || zend_string_equals_literal(Z_STR_P(val), "Yes") || + zend_string_equals_literal(Z_STR_P(val), "1")) { ZVAL_STRINGL(&new_val, "'t'", sizeof("'t'")-1); } - else if (!strcmp(Z_STRVAL_P(val), "f") || !strcmp(Z_STRVAL_P(val), "F") || - !strcmp(Z_STRVAL_P(val), "n") || !strcmp(Z_STRVAL_P(val), "N") || - !strcmp(Z_STRVAL_P(val), "false") || !strcmp(Z_STRVAL_P(val), "False") || - !strcmp(Z_STRVAL_P(val), "no") || !strcmp(Z_STRVAL_P(val), "No") || - !strcmp(Z_STRVAL_P(val), "0")) { + else if (zend_string_equals_literal(Z_STR_P(val), "f") || zend_string_equals_literal(Z_STR_P(val), "F") || + zend_string_equals_literal(Z_STR_P(val), "n") || zend_string_equals_literal(Z_STR_P(val), "N") || + zend_string_equals_literal(Z_STR_P(val), "false") || zend_string_equals_literal(Z_STR_P(val), "False") || + zend_string_equals_literal(Z_STR_P(val), "no") || zend_string_equals_literal(Z_STR_P(val), "No") || + zend_string_equals_literal(Z_STR_P(val), "0")) { ZVAL_STRINGL(&new_val, "'f'", sizeof("'f'")-1); } else { @@ -5540,7 +5539,8 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr, } else { smart_str_appendl(querystr, ZSTR_VAL(fld), ZSTR_LEN(fld)); } - if (where_cond && (Z_TYPE_P(val) == IS_TRUE || Z_TYPE_P(val) == IS_FALSE || (Z_TYPE_P(val) == IS_STRING && !strcmp(Z_STRVAL_P(val), "NULL")))) { + if (where_cond && (Z_TYPE_P(val) == IS_TRUE || Z_TYPE_P(val) == IS_FALSE || + (Z_TYPE_P(val) == IS_STRING && zend_string_equals_literal(Z_STR_P(val), "NULL")))) { smart_str_appends(querystr, " IS "); } else { smart_str_appendc(querystr, '='); From f9bdf5517a4de81d54f3d4e1ef8489befc2d5a4a Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:32:02 +0000 Subject: [PATCH 4/7] Use zend_string_equals() API instead of strcmp() in Filter extension --- ext/filter/logical_filters.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index a27e0369a244..93367fc41491 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -627,7 +627,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if ( url->scheme == NULL || /* some schemas allow the host to be empty */ - (url->host == NULL && (strcmp(ZSTR_VAL(url->scheme), "mailto") && strcmp(ZSTR_VAL(url->scheme), "news") && strcmp(ZSTR_VAL(url->scheme), "file"))) || + (url->host == NULL && (!zend_string_equals_literal(url->scheme, "mailto") && !zend_string_equals_literal(url->scheme, "news") && !zend_string_equals_literal(url->scheme, "file"))) || ((flags & FILTER_FLAG_PATH_REQUIRED) && url->path == NULL) || ((flags & FILTER_FLAG_QUERY_REQUIRED) && url->query == NULL) ) { bad_url: @@ -902,12 +902,12 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ case 1: case 0: break; case 2: - if (!strcmp("::", Z_STRVAL_P(value))) { + if (zend_string_equals_literal(Z_STR_P(value), "::")) { RETURN_VALIDATION_FAILED } break; case 3: - if (!strcmp("::1", Z_STRVAL_P(value)) || !strcmp("5f:", Z_STRVAL_P(value))) { + if (zend_string_equals_literal(Z_STR_P(value), "::1") || zend_string_equals_literal(Z_STR_P(value), "5f:")) { RETURN_VALIDATION_FAILED } break; From f81c4c56ac4ac1a49d9fb50b1f1ae8d2e238727c Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:41:08 +0000 Subject: [PATCH 5/7] Use zend_string_equals() API instead of strcmp() in Date extension --- ext/date/php_date.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index a12f00957b6e..e74a1ec22fc3 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3733,7 +3733,7 @@ static zval *date_interval_read_property(zend_object *object, zend_string *name, } #define GET_VALUE_FROM_STRUCT(n,m) \ - if (strcmp(ZSTR_VAL(name), m) == 0) { \ + if (zend_string_equals_literal(name, m)) { \ value = obj->diff->n; \ break; \ } @@ -3744,7 +3744,7 @@ static zval *date_interval_read_property(zend_object *object, zend_string *name, GET_VALUE_FROM_STRUCT(h, "h"); GET_VALUE_FROM_STRUCT(i, "i"); GET_VALUE_FROM_STRUCT(s, "s"); - if (strcmp(ZSTR_VAL(name), "f") == 0) { + if (zend_string_equals_literal(name, "f")) { fvalue = obj->diff->us / 1000000.0; break; } @@ -3782,7 +3782,7 @@ static zval *date_interval_write_property(zend_object *object, zend_string *name } #define SET_VALUE_FROM_STRUCT(n,m) \ - if (strcmp(ZSTR_VAL(name), m) == 0) { \ + if (zend_string_equals_literal(name, m)) { \ obj->diff->n = zval_get_long(value); \ break; \ } @@ -3794,7 +3794,7 @@ static zval *date_interval_write_property(zend_object *object, zend_string *name SET_VALUE_FROM_STRUCT(h, "h"); SET_VALUE_FROM_STRUCT(i, "i"); SET_VALUE_FROM_STRUCT(s, "s"); - if (strcmp(ZSTR_VAL(name), "f") == 0) { + if (zend_string_equals_literal(name, "f")) { obj->diff->us = zval_get_double(value) * 1000000; break; } @@ -3812,15 +3812,16 @@ static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string { zval *ret; - if(zend_binary_strcmp("y", sizeof("y") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("m", sizeof("m") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("d", sizeof("d") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("h", sizeof("h") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("i", sizeof("i") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("s", sizeof("s") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("f", sizeof("f") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("days", sizeof("days") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0 || - zend_binary_strcmp("invert", sizeof("invert") - 1, ZSTR_VAL(name), ZSTR_LEN(name)) == 0) { + if ( + zend_string_equals_literal(name, "y") || + zend_string_equals_literal(name, "m") || + zend_string_equals_literal(name, "d") || + zend_string_equals_literal(name, "h") || + zend_string_equals_literal(name, "i") || + zend_string_equals_literal(name, "s") || + zend_string_equals_literal(name, "f") || + zend_string_equals_literal(name, "days") || + zend_string_equals_literal(name, "invert") ) { /* Fallback to read_property. */ ret = NULL; } else { From 99dc40fe079f048a6dbfef54cd71fe8154824013 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:55:54 +0000 Subject: [PATCH 6/7] Use zend_string_equals() API instead of strcmp() in COM extension --- ext/com_dotnet/php_com_dotnet_internal.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/com_dotnet/php_com_dotnet_internal.h b/ext/com_dotnet/php_com_dotnet_internal.h index e80bf6e3126e..d2b772e063e5 100644 --- a/ext/com_dotnet/php_com_dotnet_internal.h +++ b/ext/com_dotnet/php_com_dotnet_internal.h @@ -51,9 +51,9 @@ typedef struct _php_com_dotnet_object { static inline int php_com_is_valid_object(zval *zv) { zend_class_entry *ce = Z_OBJCE_P(zv); - return strcmp("com", ce->name->val) == 0 || - strcmp("dotnet", ce->name->val) == 0 || - strcmp("variant", ce->name->val) == 0; + return zend_string_equals_literal(ce->name, "com") || + zend_string_equals_literal(ce->name, "dotnet") || + zend_string_equals_literal(ce->name, "variant"); } #define CDNO_FETCH(zv) (php_com_dotnet_object*)Z_OBJ_P(zv) From 2c90eec38de670440300d13af512556bcd594290 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 17 Mar 2021 11:50:54 +0000 Subject: [PATCH 7/7] Use zend_string_equals() API instead of strcmp() in various places --- Zend/zend_compile.c | 2 +- ext/gd/gd.c | 2 +- ext/standard/string.c | 2 +- ext/xml/xml.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index d6b30753571d..3e0eae5f57f0 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7902,7 +7902,7 @@ static bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */ ZSTR_LEN(dirname) = zend_dirname(ZSTR_VAL(dirname), ZSTR_LEN(dirname)); #endif - if (strcmp(ZSTR_VAL(dirname), ".") == 0) { + if (zend_string_equals_literal(dirname, ".")) { dirname = zend_string_extend(dirname, MAXPATHLEN, 0); #if HAVE_GETCWD ZEND_IGNORE_VALUE(VCWD_GETCWD(ZSTR_VAL(dirname), MAXPATHLEN)); diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 0b680107fd20..624fbcf244d9 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3182,7 +3182,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode) if (key == NULL) { continue; } - if (strcmp("linespacing", ZSTR_VAL(key)) == 0) { + if (zend_string_equals_literal(key, "linespacing")) { strex.flags |= gdFTEX_LINESPACE; strex.linespacing = zval_get_double(item); } diff --git a/ext/standard/string.c b/ext/standard/string.c index 2cab70c82f97..6414ec60cfef 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -4634,7 +4634,7 @@ PHP_FUNCTION(strip_tags) static zend_string *try_setlocale_str(zend_long cat, zend_string *loc) { const char *retval; - if (!strcmp("0", ZSTR_VAL(loc))) { + if (zend_string_equals_literal(loc, "0")) { loc = NULL; } else { if (ZSTR_LEN(loc) >= 255) { diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 4079a280ff21..3f7a81e6f093 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -813,7 +813,7 @@ void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL(parser->data), curtag) { if ((mytype = zend_hash_str_find(Z_ARRVAL_P(curtag),"type", sizeof("type") - 1))) { - if (!strcmp(Z_STRVAL_P(mytype), "cdata")) { + if (zend_string_equals_literal(Z_STR_P(mytype), "cdata")) { if ((myval = zend_hash_str_find(Z_ARRVAL_P(curtag), "value", sizeof("value") - 1))) { int newlen = Z_STRLEN_P(myval) + ZSTR_LEN(decoded_value); Z_STR_P(myval) = zend_string_extend(Z_STR_P(myval), newlen, 0);