com php-src: Refactor php_url struct to save memory dup in common cases: ext/curl/interface.c ext/ filter/logical_filters.c ext/openssl/xp_ssl.c
ext/p har/dirstream.c ext/phar/stream.c ext/soap/php_http .c ext/standard/ftp_fopen_wrapper.c ext/standard/ht tp_fopen_wrapper.c ext/standard/url.c
ext/standard/ url.h ext/standard/url_scanner_ex.c ext/standard/ur l_scanner_ex.re
| From: | Xinchen Hui | Date: | Sun, 06 Aug 2017 09:48:05 +0000 |
| Subject: | com php-src: Refactor php_url struct to save memory dup in common cases: ext/curl/interface.c ext/ filter/logical_filters.c ext/openssl/xp_ssl.c ext/p har/dirstream.c ext/phar/stream.c ext/soap/php_http .c ext/standard/ftp_fopen_wrapper.c ext/standard/ht tp_fopen_wrapper.c ext/standard/url.c ext/standard/ url.h ext/standard/url_scanner_ex.c ext/standard/ur l_scanner_ex.re |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98957@lists.php.net to get a copy of this message | ||
Commit: 513b0093c2b480bb752fb354012f42c446769486
Author: Xinchen Hui <laruence@gmail.com> Sun, 6 Aug 2017 17:48:05 +0800
Parents: 6546c516dd61f7f9efecbd9144c02218614d4c51
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=513b0093c2b480bb752fb354012f42c446769486
Log:
Refactor php_url struct to save memory dup in common cases
Changed paths:
M ext/curl/interface.c
M ext/filter/logical_filters.c
M ext/openssl/xp_ssl.c
M ext/phar/dirstream.c
M ext/phar/stream.c
M ext/soap/php_http.c
M ext/standard/ftp_fopen_wrapper.c
M ext/standard/http_fopen_wrapper.c
M ext/standard/url.c
M ext/standard/url.h
M ext/standard/url_scanner_ex.c
M ext/standard/url_scanner_ex.re
diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 0d1152b..fa30e45 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -210,7 +210,7 @@ static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) return FAILURE; } - if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) { + if (uri->scheme && zend_string_equals_literal_ci(uri->scheme, "file")) { php_error_docref(NULL, E_WARNING, "Protocol 'file' disabled in cURL"); php_url_free(uri); return FAILURE; diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index c203adc..e0a858a 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -532,7 +532,8 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ RETURN_VALIDATION_FAILED } - if (url->scheme != NULL && (!strcasecmp(url->scheme, "http") || !strcasecmp(url->scheme, "https"))) { + if (url->scheme != NULL && + (zend_string_equals_literal_ci(url->scheme, "http") || zend_string_equals_literal_ci(url->scheme, "https"))) { char *e, *s, *t; size_t l; @@ -540,9 +541,9 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ goto bad_url; } - s = url->host; - l = strlen(s); - e = url->host + l; + s = ZSTR_VAL(url->host); + l = ZSTR_LEN(url->host); + e = s + l; t = e - 1; /* An IPv6 enclosed by square brackets is a valid hostname */ @@ -552,7 +553,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } // Validate domain - if (!_php_filter_validate_domain(url->host, l, FILTER_FLAG_HOSTNAME)) { + if (!_php_filter_validate_domain(ZSTR_VAL(url->host), l, FILTER_FLAG_HOSTNAME)) { php_url_free(url); RETURN_VALIDATION_FAILED } @@ -561,7 +562,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(url->scheme, "mailto") && strcmp(url->scheme, "news") && strcmp(url->scheme, "file"))) || + (url->host == NULL && (strcmp(ZSTR_VAL(url->scheme), "mailto") && strcmp(ZSTR_VAL(url->scheme), "news") && strcmp(ZSTR_VAL(url->scheme), "file"))) || ((flags & FILTER_FLAG_PATH_REQUIRED) && url->path == NULL) || ((flags & FILTER_FLAG_QUERY_REQUIRED) && url->query == NULL) ) { bad_url: diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index fe7aeda..bb47f39 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2581,9 +2581,9 @@ static char *php_openssl_get_url_name(const char *resourcename, } if (url->host) { - const char * host = url->host; + const char * host = ZSTR_VAL(url->host); char * url_name = NULL; - size_t len = strlen(host); + size_t len = ZSTR_LEN(url->host); /* skip trailing dots */ while (len && host[len-1] == '.') { diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index cb95cdf..ce37a44 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -319,7 +319,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, /* we must have at the very least phar://alias.phar/ */ if (!resource->scheme || !resource->host || !resource->path) { if (resource->host && !resource->path) { - php_stream_wrapper_log_error(wrapper, options, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, ZSTR_VAL(resource->host)); php_url_free(resource); return NULL; } @@ -328,22 +328,22 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, return NULL; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar url \"%s\"", path); return NULL; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - internal_file = resource->path + 1; /* strip leading "/" */ + internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar file \"%s\" is unknown", resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar file \"%s\" is unknown", ZSTR_VAL(resource->host)); } php_url_free(resource); return NULL; @@ -446,48 +446,48 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url_from); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - if ((e = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error, 1))) { + if ((e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, 1))) { /* directory exists, or is a subdirectory of an existing file */ if (e->is_temp_dir) { efree(e->filename); efree(e); } - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); php_url_free(resource); return 0; } if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - if (phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 0, &error, 1)) { + if (phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 0, &error, 1)) { /* entry exists as a file */ - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); php_url_free(resource); return 0; } if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; @@ -500,14 +500,14 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo entry.is_zip = 1; } - entry.filename = estrdup(resource->path + 1); + entry.filename = estrdup(ZSTR_VAL(resource->path) + 1); if (phar->is_tar) { entry.is_tar = 1; entry.tar_type = TAR_DIR; } - entry.filename_len = strlen(resource->path + 1); + entry.filename_len = ZSTR_LEN(resource->path) - 1; php_url_free(resource); entry.is_dir = 1; entry.phar = phar; @@ -581,29 +581,29 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - path_len = strlen(resource->path+1); + path_len = ZSTR_LEN(resource->path) - 1; - if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, path_len, 2, &error, 1))) { + if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, 1))) { if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); } php_url_free(resource); return 0; @@ -615,7 +615,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options zend_hash_move_forward(&phar->manifest) ) { if (ZSTR_LEN(str_key) > path_len && - memcmp(ZSTR_VAL(str_key), resource->path+1, path_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource->path)+1, path_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[path_len])) { php_stream_wrapper_log_error(wrapper, options, "phar error: Directory not empty"); if (entry->is_temp_dir) { @@ -632,7 +632,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options zend_hash_move_forward(&phar->virtual_dirs)) { if (ZSTR_LEN(str_key) > path_len && - memcmp(ZSTR_VAL(str_key), resource->path+1, path_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource->path)+1, path_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[path_len])) { php_stream_wrapper_log_error(wrapper, options, "phar error: Directory not empty"); if (entry->is_temp_dir) { @@ -646,7 +646,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options } if (entry->is_temp_dir) { - zend_hash_str_del(&phar->virtual_dirs, resource->path+1, path_len); + zend_hash_str_del(&phar->virtual_dirs, ZSTR_VAL(resource->path)+1, path_len); efree(entry->filename); efree(entry); } else { diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 97e1dc6..65eabd9 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -84,19 +84,21 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const return NULL; } resource = ecalloc(1, sizeof(php_url)); - resource->scheme = estrndup("phar", 4); - resource->host = arch; + resource->scheme = zend_string_init("phar", 4, 0); + resource->host = zend_string_init(arch, arch_len, 0); + efree(arch); + resource->path = zend_string_init(entry, entry_len, 0); + efree(entry); - resource->path = entry; #if MBO_0 if (resource) { fprintf(stderr, "Alias: %s\n", alias); - fprintf(stderr, "Scheme: %s\n", resource->scheme); + fprintf(stderr, "Scheme: %s\n", ZSTR_VAL(resource->scheme)); /* fprintf(stderr, "User: %s\n", resource->user);*/ /* fprintf(stderr, "Pass: %s\n", resource->pass ? "***" : NULL);*/ - fprintf(stderr, "Host: %s\n", resource->host); + fprintf(stderr, "Host: %s\n", ZSTR_VAL(resource->host)); /* fprintf(stderr, "Port: %d\n", resource->port);*/ - fprintf(stderr, "Path: %s\n", resource->path); + fprintf(stderr, "Path: %s\n", ZSTR_VAL(resource->path)); /* fprintf(stderr, "Query: %s\n", resource->query);*/ /* fprintf(stderr, "Fragment: %s\n", resource->fragment);*/ } @@ -104,7 +106,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { phar_archive_data *pphar = NULL, *phar; - if (PHAR_G(request_init) && PHAR_G(phar_fname_map.u.flags) && NULL == (pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), arch, arch_len))) { + if (PHAR_G(request_init) && PHAR_G(phar_fname_map.u.flags) && NULL == (pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host))) { pphar = NULL; } if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) { @@ -114,7 +116,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const php_url_free(resource); return NULL; } - if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, 0, options, &phar, &error) == FAILURE) + if (phar_open_or_create_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, 0, options, &phar, &error) == FAILURE) { if (error) { if (!(options & PHP_STREAM_URL_STAT_QUIET)) { @@ -127,7 +129,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const } if (phar->is_persistent && FAILURE == phar_copy_on_write(&phar)) { if (error) { - spprintf(&error, 0, "Cannot open cached phar '%s' as writeable, copy on write failed", resource->host); + spprintf(&error, 0, "Cannot open cached phar '%s' as writeable, copy on write failed", ZSTR_VAL(resource->host)); if (!(options & PHP_STREAM_URL_STAT_QUIET)) { php_stream_wrapper_log_error(wrapper, options, "%s", error); } @@ -137,7 +139,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const return NULL; } } else { - if (phar_open_from_filename(resource->host, arch_len, NULL, 0, options, NULL, &error) == FAILURE) + if (phar_open_from_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, options, NULL, &error) == FAILURE) { if (error) { if (!(options & PHP_STREAM_URL_STAT_QUIET)) { @@ -179,24 +181,24 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha return NULL; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", path); return NULL; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); /* strip leading "/" */ - internal_file = estrdup(resource->path + 1); + internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { - if (NULL == (idata = phar_get_or_create_entry_data(resource->host, host_len, internal_file, strlen(internal_file), mode, 0, &error, 1))) { + if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), mode, 0, &error, 1))) { if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: file \"%s\" could not be created in phar \"%s\"", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: file \"%s\" could not be created in phar \"%s\"", internal_file, ZSTR_VAL(resource->host)); } efree(internal_file); php_url_free(resource); @@ -239,14 +241,14 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha } else { if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) { /* retrieve the stub */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, NULL)) { - php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", resource->host); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, NULL)) { + php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", ZSTR_VAL(resource->host)); efree(internal_file); php_url_free(resource); return NULL; } if (phar->is_tar || phar->is_zip) { - if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) { goto idata_error; } efree(internal_file); @@ -284,13 +286,13 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha } } /* read-only access is allowed to magic files in .phar directory */ - if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) { idata_error: if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" is not a file in phar \"%s\"", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" is not a file in phar \"%s\"", internal_file, ZSTR_VAL(resource->host)); } efree(internal_file); php_url_free(resource); @@ -569,17 +571,17 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f return FAILURE; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); return FAILURE; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - internal_file = resource->path + 1; /* strip leading "/" */ + internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */ /* find the phar in our trusty global hash indexed by alias (host of phar://blah.phar/file.whatever) */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { php_url_free(resource); if (error) { efree(error); @@ -679,16 +681,16 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), resource->host, host_len); + pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host); if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: write operations disabled by the php.ini setting phar.readonly"); @@ -696,9 +698,9 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int } /* need to copy to strip leading "/", will get touched again */ - internal_file = estrdup(resource->path + 1); - internal_file_len = strlen(internal_file); - if (FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, internal_file_len, "r", 0, &error, 1)) { + internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); + internal_file_len = ZSTR_LEN(resource->path) - 1; + if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, internal_file_len, "r", 0, &error, 1)) { /* constraints of fp refcount were not met */ if (error) { php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error); @@ -715,7 +717,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int } if (idata->internal_file->fp_refcount > 1) { /* more than just our fp resource is open for this file */ - php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink", internal_file, ZSTR_VAL(resource->host)); efree(internal_file); php_url_free(resource); phar_entry_delref(idata); @@ -748,7 +750,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_from); return 0; } - if (SUCCESS != phar_get_archive(&pfrom, resource_from->host, strlen(resource_from->host), NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&pfrom, ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, &error)) { pfrom = NULL; if (error) { efree(error); @@ -765,7 +767,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_to); return 0; } - if (SUCCESS != phar_get_archive(&pto, resource_to->host, strlen(resource_to->host), NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&pto, ZSTR_VAL(resource_to->host), ZSTR_LEN(resource_to->host), NULL, 0, &error)) { if (error) { efree(error); } @@ -777,7 +779,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (strcmp(resource_from->host, resource_to->host)) { + if (!zend_string_equals(resource_from->host, resource_to->host)) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\", not within the same phar archive", url_from, url_to); @@ -799,23 +801,23 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (strcasecmp("phar", resource_from->scheme)) { + if (!zend_string_equals_literal_ci(resource_from->scheme, "phar")) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": not a phar stream url \"%s\"", url_from, url_to, url_from); return 0; } - if (strcasecmp("phar", resource_to->scheme)) { + if (!zend_string_equals_literal_ci(resource_to->scheme, "phar")) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": not a phar stream url \"%s\"", url_from, url_to, url_to); return 0; } - host_len = strlen(resource_from->host); + host_len = ZSTR_LEN(resource_from->host); - if (SUCCESS != phar_get_archive(&phar, resource_from->host, host_len, NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": %s", url_from, url_to, error); @@ -830,7 +832,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (NULL != (entry = zend_hash_str_find_ptr(&(phar->manifest), resource_from->path+1, strlen(resource_from->path)-1))) { + if (NULL != (entry = zend_hash_str_find_ptr(&(phar->manifest), ZSTR_VAL(resource_from->path)+1, ZSTR_LEN(resource_from->path)-1))) { phar_entry_info new, *source; /* perform rename magic */ @@ -850,9 +852,9 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from source = entry; /* add to the manifest, and then store the pointer to the new guy in entry */ - entry = zend_hash_str_add_mem(&(phar->manifest), resource_to->path+1, strlen(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info)); + entry = zend_hash_str_add_mem(&(phar->manifest), ZSTR_VAL(resource_to->path)+1, ZSTR_LEN(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info)); - entry->filename = estrdup(resource_to->path+1); + entry->filename = estrndup(ZSTR_VAL(resource_to->path)+1, ZSTR_LEN(resource_to->path)-1); if (FAILURE == phar_copy_entry_fp(source, entry, &error)) { php_url_free(resource_from); php_url_free(resource_to); @@ -866,7 +868,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from entry->filename_len = strlen(entry->filename); is_dir = entry->is_dir; } else { - is_dir = zend_hash_str_exists(&(phar->virtual_dirs), resource_from->path+1, strlen(resource_from->path)-1); + is_dir = zend_hash_str_exists(&(phar->virtual_dirs), ZSTR_VAL(resource_from->path)+1, ZSTR_LEN(resource_from->path)-1); if (!is_dir) { /* file does not exist */ php_url_free(resource_from); @@ -882,19 +884,19 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from Bucket *b; zend_string *str_key; zend_string *new_str_key; - uint32_t from_len = strlen(resource_from->path+1); - uint32_t to_len = strlen(resource_to->path+1); + uint32_t from_len = ZSTR_LEN(resource_from->path) - 1; + uint32_t to_len = ZSTR_LEN(resource_to->path) - 1; ZEND_HASH_FOREACH_BUCKET(&phar->manifest, b) { str_key = b->key; entry = Z_PTR(b->val); if (!entry->is_deleted && ZSTR_LEN(str_key) > from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[from_len])) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; @@ -915,11 +917,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from ZEND_HASH_FOREACH_BUCKET(&phar->virtual_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && (ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; @@ -933,11 +935,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from ZEND_HASH_FOREACH_BUCKET(&phar->mounted_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && (ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index c0b5f61..d8d8f95 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -179,7 +179,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph port = Z_LVAL_P(proxy_port); *use_proxy = 1; } else { - host = phpurl->host; + host = ZSTR_VAL(phpurl->host); port = phpurl->port; } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout")-1)) != NULL && @@ -243,18 +243,18 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph /* Set peer_name or name verification will try to use the proxy server name */ if (!context || (tmp = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) { - ZVAL_STRING(&ssl_proxy_peer_name, phpurl->host); + ZVAL_STR_COPY(&ssl_proxy_peer_name, phpurl->host); php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name); zval_ptr_dtor(&ssl_proxy_peer_name); } smart_str_append_const(&soap_headers, "CONNECT "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); smart_str_append_const(&soap_headers, " HTTP/1.1\r\n"); smart_str_append_const(&soap_headers, "Host: "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); if (phpurl->port != 80) { smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); @@ -454,9 +454,9 @@ try_again: } use_ssl = 0; - if (phpurl->scheme != NULL && strcmp(phpurl->scheme, "https") == 0) { + if (phpurl->scheme != NULL && zend_string_equals_literal(phpurl->scheme, "https")) { use_ssl = 1; - } else if (phpurl->scheme == NULL || strcmp(phpurl->scheme, "http") != 0) { + } else if (phpurl->scheme == NULL || !zend_string_equals_literal(phpurl->scheme, "http")) { php_url_free(phpurl); if (request != buf) { zend_string_release(request); @@ -489,10 +489,10 @@ try_again: if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1)) != NULL && (orig = (php_url *) zend_fetch_resource_ex(tmp, "httpurl", le_url)) != NULL && ((use_proxy && !use_ssl) || - (((use_ssl && orig->scheme != NULL && strcmp(orig->scheme, "https") == 0) || + (((use_ssl && orig->scheme != NULL && zend_string_equals_literal(orig->scheme, "https")) || (!use_ssl && orig->scheme == NULL) || - (!use_ssl && strcmp(orig->scheme, "https") != 0)) && - strcmp(orig->host, phpurl->host) == 0 && + (!use_ssl && !zend_string_equals_literal(orig->scheme, "https"))) && + strcmp(ZSTR_VAL(orig->host), ZSTR_VAL(phpurl->host)) == 0 && orig->port == phpurl->port))) { } else { php_stream_close(stream); @@ -553,24 +553,24 @@ try_again: smart_str_append_const(&soap_headers, "POST "); if (use_proxy && !use_ssl) { - smart_str_appends(&soap_headers, phpurl->scheme); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->scheme)); smart_str_append_const(&soap_headers, "://"); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); } if (phpurl->path) { - smart_str_appends(&soap_headers, phpurl->path); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path)); } else { smart_str_appendc(&soap_headers, '/'); } if (phpurl->query) { smart_str_appendc(&soap_headers, '?'); - smart_str_appends(&soap_headers, phpurl->query); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query)); } if (phpurl->fragment) { smart_str_appendc(&soap_headers, '#'); - smart_str_appends(&soap_headers, phpurl->fragment); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment)); } if (http_1_1) { smart_str_append_const(&soap_headers, " HTTP/1.1\r\n"); @@ -578,7 +578,7 @@ try_again: smart_str_append_const(&soap_headers, " HTTP/1.0\r\n"); } smart_str_append_const(&soap_headers, "Host: "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); if (phpurl->port != (use_ssl?443:80)) { smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); @@ -702,13 +702,13 @@ try_again: PHP_MD5Init(&md5ctx); PHP_MD5Update(&md5ctx, (unsigned char*)"POST:", sizeof("POST:")-1); if (phpurl->path) { - PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->path, strlen(phpurl->path)); + PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->path), ZSTR_LEN(phpurl->path)); } else { PHP_MD5Update(&md5ctx, (unsigned char*)"/", 1); } if (phpurl->query) { PHP_MD5Update(&md5ctx, (unsigned char*)"?", 1); - PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->query, strlen(phpurl->query)); + PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->query), ZSTR_LEN(phpurl->query)); } PHP_MD5Final(hash, &md5ctx); @@ -750,17 +750,17 @@ try_again: } smart_str_append_const(&soap_headers, "\", uri=\""); if (phpurl->path) { - smart_str_appends(&soap_headers, phpurl->path); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path)); } else { smart_str_appendc(&soap_headers, '/'); } if (phpurl->query) { smart_str_appendc(&soap_headers, '?'); - smart_str_appends(&soap_headers, phpurl->query); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query)); } if (phpurl->fragment) { smart_str_appendc(&soap_headers, '#'); - smart_str_appends(&soap_headers, phpurl->fragment); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment)); } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) { @@ -835,10 +835,10 @@ try_again: zval *tmp; if (((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 1)) == NULL || Z_TYPE_P(tmp) != IS_STRING || - strncmp(phpurl->path?phpurl->path:"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) && + strncmp(phpurl->path?ZSTR_VAL(phpurl->path):"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) && ((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 2)) == NULL || Z_TYPE_P(tmp) != IS_STRING || - in_domain(phpurl->host,Z_STRVAL_P(tmp))) && + in_domain(ZSTR_VAL(phpurl->host),Z_STRVAL_P(tmp))) && (use_ssl || (tmp = zend_hash_index_find(Z_ARRVAL_P(data), 3)) == NULL)) { smart_str_append(&soap_headers, key); smart_str_appendc(&soap_headers, '='); @@ -1006,14 +1006,15 @@ try_again: } } if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 1)) { - char *t = phpurl->path?phpurl->path:"/"; + char *t = phpurl->path?ZSTR_VAL(phpurl->path):"/"; char *c = strrchr(t, '/'); if (c) { add_index_stringl(&zcookie, 1, t, c-t); } } if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 2)) { - add_index_string(&zcookie, 2, phpurl->host); + add_index_str(&zcookie, 2, phpurl->host); + GC_REFCOUNT(phpurl->host)++; } zend_symtable_update(Z_ARRVAL_P(cookies), name.s, &zcookie); @@ -1108,26 +1109,27 @@ try_again: zend_string_release(http_body); efree(loc); if (new_url->scheme == NULL && new_url->path != NULL) { - new_url->scheme = phpurl->scheme ? estrdup(phpurl->scheme) : NULL; - new_url->host = phpurl->host ? estrdup(phpurl->host) : NULL; + new_url->scheme = phpurl->scheme ? zend_string_copy(phpurl->scheme) : NULL; + new_url->host = phpurl->host ? zend_string_copy(phpurl->host) : NULL; new_url->port = phpurl->port; - if (new_url->path && new_url->path[0] != '/') { + if (new_url->path && ZSTR_VAL(new_url->path)[0] != '/') { if (phpurl->path) { - char *t = phpurl->path; + char *t = ZSTR_VAL(phpurl->path); char *p = strrchr(t, '/'); if (p) { - char *s = emalloc((p - t) + strlen(new_url->path) + 2); - strncpy(s, t, (p - t) + 1); - s[(p - t) + 1] = 0; - strcat(s, new_url->path); - efree(new_url->path); + zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_url->path) + 2, 0); + strncpy(ZSTR_VAL(s), t, (p - t) + 1); + ZSTR_VAL(s)[(p - t) + 1] = 0; + strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path)); + zend_string_release(new_url->path); new_url->path = s; } } else { - char *s = emalloc(strlen(new_url->path) + 2); - s[0] = '/'; s[1] = 0; - strcat(s, new_url->path); - efree(new_url->path); + zend_string *s = zend_string_alloc(ZSTR_LEN(new_url->path) + 2, 0); + ZSTR_VAL(s)[0] = '/'; + ZSTR_VAL(s)[1] = 0; + strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path)); + zend_string_release(new_url->path); new_url->path = s; } } @@ -1202,13 +1204,13 @@ try_again: add_property_zval_ex(this_ptr, "_digest", sizeof("_digest")-1, &digest); *new_url = *phpurl; - if (phpurl->scheme) phpurl->scheme = estrdup(phpurl->scheme); - if (phpurl->user) phpurl->user = estrdup(phpurl->user); - if (phpurl->pass) phpurl->pass = estrdup(phpurl->pass); - if (phpurl->host) phpurl->host = estrdup(phpurl->host); - if (phpurl->path) phpurl->path = estrdup(phpurl->path); - if (phpurl->query) phpurl->query = estrdup(phpurl->query); - if (phpurl->fragment) phpurl->fragment = estrdup(phpurl->fragment); + if (phpurl->scheme) phpurl->scheme = zend_string_copy(phpurl->scheme); + if (phpurl->user) phpurl->user = zend_string_copy(phpurl->user); + if (phpurl->pass) phpurl->pass = zend_string_copy(phpurl->pass); + if (phpurl->host) phpurl->host = zend_string_copy(phpurl->host); + if (phpurl->path) phpurl->path = zend_string_copy(phpurl->path); + if (phpurl->query) phpurl->query = zend_string_copy(phpurl->query); + if (phpurl->fragment) phpurl->fragment = zend_string_copy(phpurl->fragment); phpurl = new_url; efree(auth); diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index d54f2f6..b548ddd 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -135,7 +135,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char { php_stream *stream = NULL, *reuseid = NULL; php_url *resource = NULL; - int result, use_ssl, use_ssl_on_data = 0, tmp_len; + int result, use_ssl, use_ssl_on_data = 0; char tmp_line[512]; char *transport; int transport_len; @@ -148,13 +148,13 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char return NULL; } - use_ssl = resource->scheme && (strlen(resource->scheme) > 3) && resource->scheme[3] == 's'; + use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 3) && ZSTR_VAL(resource->scheme)[3] == 's'; /* use port 21 if one wasn't specified */ if (resource->port == 0) resource->port = 21; - transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", resource->host, resource->port); + transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", ZSTR_VAL(resource->host), resource->port); stream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL); efree(transport); if (stream == NULL) { @@ -245,11 +245,11 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char /* send the user name */ if (resource->user != NULL) { - tmp_len = (int)php_raw_url_decode(resource->user, (int)strlen(resource->user)); + ZSTR_LEN(resource->user) = php_raw_url_decode(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user)); - PHP_FTP_CNTRL_CHK(resource->user, tmp_len, "Invalid login %s") + PHP_FTP_CNTRL_CHK(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user), "Invalid login %s") - php_stream_printf(stream, "USER %s\r\n", resource->user); + php_stream_printf(stream, "USER %s\r\n", ZSTR_VAL(resource->user)); } else { php_stream_write_string(stream, "USER anonymous\r\n"); } @@ -262,11 +262,11 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, tmp_line, 0); if (resource->pass != NULL) { - tmp_len = (int)php_raw_url_decode(resource->pass, (int)strlen(resource->pass)); + ZSTR_LEN(resource->pass) = php_raw_url_decode(ZSTR_VAL(resource->pass), ZSTR_LEN(resource->pass)); - PHP_FTP_CNTRL_CHK(resource->pass, tmp_len, "Invalid password %s") + PHP_FTP_CNTRL_CHK(resource->pass, ZSTR_LEN(resource->pass), "Invalid password %s") - php_stream_printf(stream, "PASS %s\r\n", resource->pass); + php_stream_printf(stream, "PASS %s\r\n", ZSTR_VAL(resource->pass)); } else { /* if the user has configured who they are, send that as the password */ @@ -548,11 +548,11 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa /* Append */ memcpy(tmp_line, "APPE", sizeof("APPE")); } - php_stream_printf(stream, "%s %s\r\n", tmp_line, (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "%s %s\r\n", tmp_line, (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); /* open the data channel */ if (hoststart == NULL) { - hoststart = resource->host; + hoststart = ZSTR_VAL(resource->host); } transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", hoststart, portno); datastream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL); @@ -719,7 +719,7 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat /* open the data channel */ if (hoststart == NULL) { - hoststart = resource->host; + hoststart = ZSTR_VAL(resource->host); } datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0); @@ -727,7 +727,7 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat goto opendir_errexit; } - php_stream_printf(stream, "NLST %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "NLST %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result != 150 && result != 125) { @@ -792,7 +792,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, } ssb->sb.st_mode = 0644; /* FTP won't give us a valid mode, so approximate one based on being readable */ - php_stream_printf(stream, "CWD %s\r\n", (resource->path != NULL ? resource->path : "/")); /* If we can CWD to it, it's a directory (maybe a link, but we can't tell) */ + php_stream_printf(stream, "CWD %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); /* If we can CWD to it, it's a directory (maybe a link, but we can't tell) */ result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { ssb->sb.st_mode |= S_IFREG; @@ -808,7 +808,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, goto stat_errexit; } - php_stream_printf(stream, "SIZE %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "SIZE %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { /* Failure either means it doesn't exist @@ -823,7 +823,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, ssb->sb.st_size = atoi(tmp_line + 4); } - php_stream_printf(stream, "MDTM %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "MDTM %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result == 213) { char *p = tmp_line + 4; @@ -922,7 +922,7 @@ static int php_stream_ftp_unlink(php_stream_wrapper *wrapper, const char *url, i } /* Attempt to delete the file */ - php_stream_printf(stream, "DELE %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "DELE %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { @@ -965,10 +965,10 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr !resource_to || !resource_from->scheme || !resource_to->scheme || - strcmp(resource_from->scheme, resource_to->scheme) || + !zend_string_equals(resource_from->scheme, resource_to->scheme) || !resource_from->host || !resource_to->host || - strcmp(resource_from->host, resource_to->host) || + !zend_string_equals(resource_from->host, resource_to->host) || (resource_from->port != resource_to->port && resource_from->port * resource_to->port != 0 && resource_from->port + resource_to->port != 21) || @@ -980,13 +980,13 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr stream = php_ftp_fopen_connect(wrapper, url_from, "r", 0, NULL, context, NULL, NULL, NULL, NULL); if (!stream) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "Unable to connect to %s", resource_from->host); + php_error_docref(NULL, E_WARNING, "Unable to connect to %s", ZSTR_VAL(resource_from->host)); } goto rename_errexit; } /* Rename FROM */ - php_stream_printf(stream, "RNFR %s\r\n", (resource_from->path != NULL ? resource_from->path : "/")); + php_stream_printf(stream, "RNFR %s\r\n", (resource_from->path != NULL ? ZSTR_VAL(resource_from->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 300 || result > 399) { @@ -997,7 +997,7 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr } /* Rename TO */ - php_stream_printf(stream, "RNTO %s\r\n", (resource_to->path != NULL ? resource_to->path : "/")); + php_stream_printf(stream, "RNTO %s\r\n", (resource_to->path != NULL ? ZSTR_VAL(resource_to->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { @@ -1051,14 +1051,14 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in } if (!recursive) { - php_stream_printf(stream, "MKD %s\r\n", resource->path); + php_stream_printf(stream, "MKD %s\r\n", ZSTR_VAL(resource->path)); result = GET_FTP_RESULT(stream); } else { /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ char *p, *e, *buf; - buf = estrdup(resource->path); - e = buf + strlen(buf); + buf = estrndup(ZSTR_VAL(resource->path), ZSTR_LEN(resource->path)); + e = buf + ZSTR_LEN(resource->path); /* find a top level directory we need to create */ while ((p = strrchr(buf, '/'))) { @@ -1071,7 +1071,7 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in } } if (p == buf) { - php_stream_printf(stream, "MKD %s\r\n", resource->path); + php_stream_printf(stream, "MKD %s\r\n", ZSTR_VAL(resource->path)); result = GET_FTP_RESULT(stream); } else { php_stream_printf(stream, "MKD %s\r\n", buf); diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 7208404..f0881c2 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -152,7 +152,8 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, return NULL; } - if (strncasecmp(resource->scheme, "http", sizeof("http")) && strncasecmp(resource->scheme, "https", sizeof("https"))) { + if (!zend_string_equals_literal_ci(resource->scheme, "http") && + !zend_string_equals_literal_ci(resource->scheme, "https")) { if (!context || (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "proxy")) == NULL || Z_TYPE_P(tmpzval) != IS_STRING || @@ -176,7 +177,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, return NULL; } - use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's'; + use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) && ZSTR_VAL(resource->scheme)[4] == 's'; /* choose default ports */ if (use_ssl && resource->port == 0) resource->port = 443; @@ -191,7 +192,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, transport_len = Z_STRLEN_P(tmpzval); transport_string = estrndup(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval)); } else { - transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port); + transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", ZSTR_VAL(resource->host), resource->port); } } @@ -234,13 +235,13 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, /* Set peer_name or name verification will try to use the proxy server name */ if (!context || (tmpzval = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) { - ZVAL_STRING(&ssl_proxy_peer_name, resource->host); + ZVAL_STR_COPY(&ssl_proxy_peer_name, resource->host); php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name); zval_ptr_dtor(&ssl_proxy_peer_name); } smart_str_appendl(&header, "CONNECT ", sizeof("CONNECT ")-1); - smart_str_appends(&header, resource->host); + smart_str_appends(&header, ZSTR_VAL(resource->host)); smart_str_appendc(&header, ':'); smart_str_append_unsigned(&header, resource->port); smart_str_appendl(&header, " HTTP/1.0\r\n", sizeof(" HTTP/1.0\r\n")-1); @@ -388,8 +389,8 @@ finish: /* Send the traditional /path/to/file?query_string */ /* file */ - if (resource->path && *resource->path) { - smart_str_appends(&req_buf, resource->path); + if (resource->path && ZSTR_LEN(resource->path)) { + smart_str_appends(&req_buf, ZSTR_VAL(resource->path)); } else { smart_str_appendc(&req_buf, '/'); } @@ -397,7 +398,7 @@ finish: /* query string */ if (resource->query) { smart_str_appendc(&req_buf, '?'); - smart_str_appends(&req_buf, resource->query); + smart_str_appends(&req_buf, ZSTR_VAL(resource->query)); } } @@ -531,15 +532,15 @@ finish: zend_string *stmp; /* decode the strings first */ - php_url_decode(resource->user, strlen(resource->user)); + php_url_decode(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user)); - strcpy(scratch, resource->user); + strcpy(scratch, ZSTR_VAL(resource->user)); strcat(scratch, ":"); /* Note: password is optional! */ if (resource->pass) { - php_url_decode(resource->pass, strlen(resource->pass)); - strcat(scratch, resource->pass); + php_url_decode(ZSTR_VAL(resource->pass), ZSTR_LEN(resource->pass)); + strcat(scratch, ZSTR_VAL(resource->pass)); } stmp = php_base64_encode((unsigned char*)scratch, strlen(scratch)); @@ -564,7 +565,7 @@ finish: /* Send Host: header so name-based virtual hosts work */ if ((have_header & HTTP_HEADER_HOST) == 0) { smart_str_appends(&req_buf, "Host: "); - smart_str_appends(&req_buf, resource->host); + smart_str_appends(&req_buf, ZSTR_VAL(resource->host)); if ((use_ssl && resource->port != 443 && resource->port != 0) || (!use_ssl && resource->port != 80 && resource->port != 0)) { smart_str_appendc(&req_buf, ':'); @@ -855,21 +856,24 @@ finish: { if (*location != '/') { if (*(location+1) != '\0' && resource->path) { - char *s = strrchr(resource->path, '/'); + char *s = strrchr(ZSTR_VAL(resource->path), '/'); if (!s) { - s = resource->path; - if (!s[0]) { - efree(s); - s = resource->path = estrdup("/"); + s = ZSTR_VAL(resource->path); + if (!ZSTR_LEN(resource->path)) { + zend_string_release(resource->path); + resource->path = zend_string_init("/", 1, 0); + s = ZSTR_VAL(resource->path); } else { *s = '/'; } } s[1] = '\0'; - if (resource->path && *(resource->path) == '/' && *(resource->path + 1) == '\0') { - snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", resource->path, location); + if (resource->path && + ZSTR_VAL(resource->path)[0] == '/' && + ZSTR_VAL(resource->path)[1] == '\0') { + snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", ZSTR_VAL(resource->path), location); } else { - snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", resource->path, location); + snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", ZSTR_VAL(resource->path), location); } } else { snprintf(loc_path, sizeof(loc_path) - 1, "/%s", location); @@ -878,9 +882,9 @@ finish: strlcpy(loc_path, location, sizeof(loc_path)); } if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->host, resource->port, loc_path); + snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", ZSTR_VAL(resource->scheme), ZSTR_VAL(resource->host), resource->port, loc_path); } else { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->host, loc_path); + snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", ZSTR_VAL(resource->scheme), ZSTR_VAL(resource->host), loc_path); } } else { strlcpy(new_path, location, sizeof(new_path)); @@ -896,9 +900,8 @@ finish: #define CHECK_FOR_CNTRL_CHARS(val) { \ if (val) { \ unsigned char *s, *e; \ - size_t l; \ - l = php_url_decode(val, strlen(val)); \ - s = (unsigned char*)val; e = s + l; \ + ZSTR_LEN(val) = php_url_decode(ZSTR_VAL(val), ZSTR_LEN(val)); \ + s = (unsigned char*)ZSTR_VAL(val); e = s + ZSTR_LEN(val); \ while (s < e) { \ if (iscntrl(*s)) { \ php_stream_wrapper_log_error(wrapper, options, "Invalid redirect URL! %s", new_path); \ @@ -910,9 +913,9 @@ finish: } /* check for control characters in login, password & path */ if (strncasecmp(new_path, "http://", sizeof("http://") - 1) || strncasecmp(new_path, "https://", sizeof("https://") - 1)) { - CHECK_FOR_CNTRL_CHARS(resource->user) - CHECK_FOR_CNTRL_CHARS(resource->pass) - CHECK_FOR_CNTRL_CHARS(resource->path) + CHECK_FOR_CNTRL_CHARS(resource->user); + CHECK_FOR_CNTRL_CHARS(resource->pass); + CHECK_FOR_CNTRL_CHARS(resource->path); } stream = php_stream_url_wrap_http_ex( wrapper, new_path, mode, options, opened_path, context, diff --git a/ext/standard/url.c b/ext/standard/url.c index a3a19a2..e909eee 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -42,19 +42,19 @@ PHPAPI void php_url_free(php_url *theurl) { if (theurl->scheme) - efree(theurl->scheme); + zend_string_release(theurl->scheme); if (theurl->user) - efree(theurl->user); + zend_string_release(theurl->user); if (theurl->pass) - efree(theurl->pass); + zend_string_release(theurl->pass); if (theurl->host) - efree(theurl->host); + zend_string_release(theurl->host); if (theurl->path) - efree(theurl->path); + zend_string_release(theurl->path); if (theurl->query) - efree(theurl->query); + zend_string_release(theurl->query); if (theurl->fragment) - efree(theurl->fragment); + zend_string_release(theurl->fragment); efree(theurl); } /* }}} */ @@ -124,8 +124,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) } if (e + 1 == ue) { /* only scheme is available */ - ret->scheme = estrndup(s, (e - s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e - s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); return ret; } @@ -146,18 +146,18 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) goto parse_port; } - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); s = e + 1; goto just_path; } else { - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); if (e + 2 < ue && *(e + 2) == '/') { s = e + 3; - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { + if (zend_string_equals_literal_ci(ret->scheme, "file")) { if (e + 3 < ue && *(e + 3) == '/') { /* support windows drive letters as in: file:///c:/somedir/file.txt @@ -193,13 +193,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) s += 2; } } else { - if (ret->scheme) efree(ret->scheme); - efree(ret); + php_url_free(ret); return NULL; } } else if (p == pp && pp == ue) { - if (ret->scheme) efree(ret->scheme); - efree(ret); + php_url_free(ret); return NULL; } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; @@ -228,15 +226,15 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) /* check for login and password */ if ((p = zend_memrchr(s, '@', (e-s)))) { if ((pp = memchr(s, ':', (p-s)))) { - ret->user = estrndup(s, (pp-s)); - php_replace_controlchars_ex(ret->user, (pp - s)); + ret->user = zend_string_init(s, (pp-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); pp++; - ret->pass = estrndup(pp, (p-pp)); - php_replace_controlchars_ex(ret->pass, (p-pp)); + ret->pass = zend_string_init(pp, (p-pp), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass)); } else { - ret->user = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->user, (p-s)); + ret->user = zend_string_init(s, (p-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); } s = p + 1; @@ -256,10 +254,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (!ret->port) { p++; if (e-p > 5) { /* port cannot be longer then 5 characters */ - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } else if (e - p > 0) { zend_long port; @@ -269,10 +264,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (port > 0 && port <= 65535) { ret->port = (unsigned short)port; } else { - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } } @@ -284,15 +276,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) /* check if we have a valid host, if we don't reject the string as url */ if ((p-s) < 1) { - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } - ret->host = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->host, (p - s)); + ret->host = zend_string_init(s, (p-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host)); if (e == ue) { return ret; @@ -307,8 +296,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p) { p++; if (p < e) { - ret->fragment = estrndup(p, (e - p)); - php_replace_controlchars_ex(ret->fragment, (e - p)); + ret->fragment = zend_string_init(p, (e - p), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment)); } e = p-1; } @@ -317,15 +306,15 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p) { p++; if (p < e) { - ret->query = estrndup(p, (e - p)); - php_replace_controlchars_ex(ret->query, (e - p)); + ret->query = zend_string_init(p, (e - p), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query)); } e = p-1; } if (s < e || s == ue) { - ret->path = estrndup(s, (e - s)); - php_replace_controlchars_ex(ret->path, (e - s)); + ret->path = zend_string_init(s, (e - s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path)); } return ret; @@ -357,28 +346,28 @@ PHP_FUNCTION(parse_url) if (key > -1) { switch (key) { case PHP_URL_SCHEME: - if (resource->scheme != NULL) RETVAL_STRING(resource->scheme); + if (resource->scheme != NULL) RETVAL_STR_COPY(resource->scheme); break; case PHP_URL_HOST: - if (resource->host != NULL) RETVAL_STRING(resource->host); + if (resource->host != NULL) RETVAL_STR_COPY(resource->host); break; case PHP_URL_PORT: if (resource->port != 0) RETVAL_LONG(resource->port); break; case PHP_URL_USER: - if (resource->user != NULL) RETVAL_STRING(resource->user); + if (resource->user != NULL) RETVAL_STR_COPY(resource->user); break; case PHP_URL_PASS: - if (resource->pass != NULL) RETVAL_STRING(resource->pass); + if (resource->pass != NULL) RETVAL_STR_COPY(resource->pass); break; case PHP_URL_PATH: - if (resource->path != NULL) RETVAL_STRING(resource->path); + if (resource->path != NULL) RETVAL_STR_COPY(resource->path); break; case PHP_URL_QUERY: - if (resource->query != NULL) RETVAL_STRING(resource->query); + if (resource->query != NULL) RETVAL_STR_COPY(resource->query); break; case PHP_URL_FRAGMENT: - if (resource->fragment != NULL) RETVAL_STRING(resource->fragment); + if (resource->fragment != NULL) RETVAL_STR_COPY(resource->fragment); break; default: php_error_docref(NULL, E_WARNING, "Invalid URL component identifier " ZEND_LONG_FMT, key); @@ -392,11 +381,11 @@ PHP_FUNCTION(parse_url) /* add the various elements to the array */ if (resource->scheme != NULL) { - ZVAL_STRING(&tmp, resource->scheme); + ZVAL_STR_COPY(&tmp, resource->scheme); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_SCHEME), &tmp); } if (resource->host != NULL) { - ZVAL_STRING(&tmp, resource->host); + ZVAL_STR_COPY(&tmp, resource->host); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_HOST), &tmp); } if (resource->port != 0) { @@ -404,23 +393,23 @@ PHP_FUNCTION(parse_url) zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PORT), &tmp); } if (resource->user != NULL) { - ZVAL_STRING(&tmp, resource->user); + ZVAL_STR_COPY(&tmp, resource->user); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_USER), &tmp); } if (resource->pass != NULL) { - ZVAL_STRING(&tmp, resource->pass); + ZVAL_STR_COPY(&tmp, resource->pass); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PASS), &tmp); } if (resource->path != NULL) { - ZVAL_STRING(&tmp, resource->path); + ZVAL_STR_COPY(&tmp, resource->path); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PATH), &tmp); } if (resource->query != NULL) { - ZVAL_STRING(&tmp, resource->query); + ZVAL_STR_COPY(&tmp, resource->query); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_QUERY), &tmp); } if (resource->fragment != NULL) { - ZVAL_STRING(&tmp, resource->fragment); + ZVAL_STR_COPY(&tmp, resource->fragment); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_FRAGMENT), &tmp); } done: diff --git a/ext/standard/url.h b/ext/standard/url.h index 7a2f20e..8c4e63e 100644 --- a/ext/standard/url.h +++ b/ext/standard/url.h @@ -21,14 +21,14 @@ #define URL_H typedef struct php_url { - char *scheme; - char *user; - char *pass; - char *host; + zend_string *scheme; + zend_string *user; + zend_string *pass; + zend_string *host; unsigned short port; - char *path; - char *query; - char *fragment; + zend_string *path; + zend_string *query; + zend_string *fragment; } php_url; PHPAPI void php_url_free(php_url *theurl); diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index 484d5d9..af8a378 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 */ +/* Generated by re2c 0.13.5 */ #line 1 "ext/standard/url_scanner_ex.re" /* +----------------------------------------------------------------------+ @@ -182,8 +182,6 @@ PHP_INI_END() static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) { php_url *url_parts; - char *tmp; - size_t tmp_len; smart_str_0(url); /* FIXME: Bug #70480 php_url_parse_ex() crashes by processing chars exceed len */ url_parts = php_url_parse_ex(ZSTR_VAL(url->s), ZSTR_LEN(url->s)); @@ -196,21 +194,23 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st /* Check protocol. Only http/https is allowed. */ if (url_parts->scheme - && strcasecmp("http", url_parts->scheme) - && strcasecmp("https", url_parts->scheme)) { + && !zend_string_equals_literal_ci(url_parts->scheme, "http") + && !zend_string_equals_literal_ci(url_parts->scheme, "https")) { smart_str_append_smart_str(dest, url); php_url_free(url_parts); return; } /* Check host whitelist. If it's not listed, do nothing. */ - if (url_parts->host - && (tmp_len = strlen(url_parts->host)) - && (tmp = php_strtolower(url_parts->host, tmp_len)) - && !zend_hash_str_find(&BG(url_adapt_session_hosts_ht), tmp, tmp_len)) { - smart_str_append_smart_str(dest, url); - php_url_free(url_parts); - return; + if (url_parts->host) { + zend_string *tmp = zend_string_tolower(url_parts->host); + if (!zend_hash_exists(&BG(url_adapt_session_hosts_ht), tmp)) { + zend_string_release(tmp); + smart_str_append_smart_str(dest, url); + php_url_free(url_parts); + return; + } + zend_string_release(tmp); } /* @@ -229,32 +229,32 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->scheme) { - smart_str_appends(dest, url_parts->scheme); + smart_str_appends(dest, ZSTR_VAL(url_parts->scheme)); smart_str_appends(dest, "://"); } else if (*(ZSTR_VAL(url->s)) == '/' && *(ZSTR_VAL(url->s)+1) == '/') { smart_str_appends(dest, "//"); } if (url_parts->user) { - smart_str_appends(dest, url_parts->user); + smart_str_appends(dest, ZSTR_VAL(url_parts->user)); if (url_parts->pass) { - smart_str_appends(dest, url_parts->pass); + smart_str_appends(dest, ZSTR_VAL(url_parts->pass)); smart_str_appendc(dest, ':'); } smart_str_appendc(dest, '@'); } if (url_parts->host) { - smart_str_appends(dest, url_parts->host); + smart_str_appends(dest, ZSTR_VAL(url_parts->host)); } if (url_parts->port) { smart_str_appendc(dest, ':'); smart_str_append_unsigned(dest, (long)url_parts->port); } if (url_parts->path) { - smart_str_appends(dest, url_parts->path); + smart_str_appends(dest, ZSTR_VAL(url_parts->path)); } smart_str_appendc(dest, '?'); if (url_parts->query) { - smart_str_appends(dest, url_parts->query); + smart_str_appends(dest, ZSTR_VAL(url_parts->query)); smart_str_appends(dest, separator); smart_str_append_smart_str(dest, url_app); } else { @@ -262,7 +262,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->fragment) { smart_str_appendc(dest, '#'); - smart_str_appends(dest, url_parts->fragment); + smart_str_appends(dest, ZSTR_VAL(url_parts->fragment)); } php_url_free(url_parts); } @@ -383,8 +383,8 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) if (url_parts->scheme) { /* Only http/https should be handled. A bit hacky check this here, but saves a URL parse. */ - if (strcasecmp(url_parts->scheme, "http") && - strcasecmp(url_parts->scheme, "https")) { + if (!zend_string_equals_literal_ci(url_parts->scheme, "http") && + !zend_string_equals_literal_ci(url_parts->scheme, "https")) { php_url_free(url_parts); return FAILURE; } @@ -394,13 +394,11 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) return SUCCESS; } if (!zend_hash_num_elements(allowed_hosts) && - check_http_host(url_parts->host) == SUCCESS) { + check_http_host(ZSTR_VAL(url_parts->host)) == SUCCESS) { php_url_free(url_parts); return SUCCESS; } - if (!zend_hash_str_find(allowed_hosts, - url_parts->host, - strlen(url_parts->host))) { + if (!zend_hash_find(allowed_hosts, url_parts->host)) { php_url_free(url_parts); return FAILURE; } @@ -513,7 +511,7 @@ state_plain_begin: state_plain: start = YYCURSOR; -#line 517 "ext/standard/url_scanner_ex.c" +#line 515 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -550,35 +548,34 @@ state_plain: 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; + if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yybm[0+yych] & 128) { - goto yy2; + goto yy4; } - goto yy5; -yy2: + ++YYCURSOR; +#line 517 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } +#line 561 "ext/standard/url_scanner_ex.c" +yy4: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yybm[0+yych] & 128) { - goto yy2; + goto yy4; } -#line 520 "ext/standard/url_scanner_ex.re" +#line 518 "ext/standard/url_scanner_ex.re" { passthru(STD_ARGS); goto state_plain; } -#line 569 "ext/standard/url_scanner_ex.c" -yy5: - ++YYCURSOR; -#line 519 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } -#line 574 "ext/standard/url_scanner_ex.c" +#line 571 "ext/standard/url_scanner_ex.c" } -#line 521 "ext/standard/url_scanner_ex.re" +#line 519 "ext/standard/url_scanner_ex.re" state_tag: start = YYCURSOR; -#line 582 "ext/standard/url_scanner_ex.c" +#line 579 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -615,27 +612,39 @@ state_tag: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy11; + if (yych <= '@') { + if (yych != ':') goto yy11; + } else { + if (yych <= 'Z') goto yy9; + if (yych <= '`') goto yy11; + if (yych >= '{') goto yy11; } +yy9: ++YYCURSOR; -#line 527 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_plain_begin; } -#line 627 "ext/standard/url_scanner_ex.c" + yych = *YYCURSOR; + goto yy14; +yy10: +#line 524 "ext/standard/url_scanner_ex.re" + { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } +#line 632 "ext/standard/url_scanner_ex.c" yy11: ++YYCURSOR; +#line 525 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_plain_begin; } +#line 637 "ext/standard/url_scanner_ex.c" +yy13: + ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy14: if (yybm[0+yych] & 128) { - goto yy11; + goto yy13; } -#line 526 "ext/standard/url_scanner_ex.re" - { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } -#line 637 "ext/standard/url_scanner_ex.c" + goto yy10; } -#line 528 "ext/standard/url_scanner_ex.re" +#line 526 "ext/standard/url_scanner_ex.re" state_next_arg_begin: @@ -644,7 +653,7 @@ state_next_arg_begin: state_next_arg: start = YYCURSOR; -#line 648 "ext/standard/url_scanner_ex.c" +#line 657 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -683,57 +692,78 @@ state_next_arg: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy18; - } - if (yych <= '>') { - if (yych == '/') goto yy21; - if (yych >= '>') goto yy22; + if (yych <= '.') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy25; + if (yych <= '\v') goto yy21; + goto yy25; + } else { + if (yych <= '\r') goto yy21; + if (yych == ' ') goto yy21; + goto yy25; + } } else { - if (yych <= 'Z') { - if (yych >= 'A') goto yy24; + if (yych <= '@') { + if (yych <= '/') goto yy17; + if (yych == '>') goto yy19; + goto yy25; } else { - if (yych <= '`') goto yy16; - if (yych <= 'z') goto yy24; + if (yych <= 'Z') goto yy23; + if (yych <= '`') goto yy25; + if (yych <= 'z') goto yy23; + goto yy25; } } -yy16: - ++YYCURSOR; yy17: -#line 539 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_plain_begin; } -#line 706 "ext/standard/url_scanner_ex.c" -yy18: ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy18; - } + if ((yych = *YYCURSOR) == '>') goto yy28; +yy18: #line 537 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_next_arg; } -#line 716 "ext/standard/url_scanner_ex.c" + { passthru(STD_ARGS); goto state_plain_begin; } +#line 724 "ext/standard/url_scanner_ex.c" +yy19: + ++YYCURSOR; +yy20: +#line 534 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } +#line 730 "ext/standard/url_scanner_ex.c" yy21: - yych = *++YYCURSOR; - if (yych != '>') goto yy17; + ++YYCURSOR; + yych = *YYCURSOR; + goto yy27; yy22: +#line 535 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_next_arg; } +#line 738 "ext/standard/url_scanner_ex.c" +yy23: ++YYCURSOR; #line 536 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } -#line 724 "ext/standard/url_scanner_ex.c" -yy24: - ++YYCURSOR; -#line 538 "ext/standard/url_scanner_ex.re" { --YYCURSOR; STATE = STATE_ARG; goto state_arg; } -#line 729 "ext/standard/url_scanner_ex.c" +#line 743 "ext/standard/url_scanner_ex.c" +yy25: + yych = *++YYCURSOR; + goto yy18; +yy26: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy27: + if (yybm[0+yych] & 128) { + goto yy26; + } + goto yy22; +yy28: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy20; } -#line 540 "ext/standard/url_scanner_ex.re" +#line 538 "ext/standard/url_scanner_ex.re" state_arg: start = YYCURSOR; -#line 737 "ext/standard/url_scanner_ex.c" +#line 767 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -770,35 +800,42 @@ state_arg: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yych <= '@') goto yy28; - if (yych <= 'Z') goto yy30; - if (yych <= '`') goto yy28; - if (yych <= 'z') goto yy30; -yy28: + if (yych <= '@') goto yy33; + if (yych <= 'Z') goto yy31; + if (yych <= '`') goto yy33; + if (yych >= '{') goto yy33; +yy31: ++YYCURSOR; -#line 546 "ext/standard/url_scanner_ex.re" + yych = *YYCURSOR; + goto yy36; +yy32: +#line 543 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } +#line 817 "ext/standard/url_scanner_ex.c" +yy33: + ++YYCURSOR; +#line 544 "ext/standard/url_scanner_ex.re" { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; } -#line 784 "ext/standard/url_scanner_ex.c" -yy30: +#line 822 "ext/standard/url_scanner_ex.c" +yy35: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy36: if (yybm[0+yych] & 128) { - goto yy30; + goto yy35; } -#line 545 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } -#line 794 "ext/standard/url_scanner_ex.c" + goto yy32; } -#line 547 "ext/standard/url_scanner_ex.re" +#line 545 "ext/standard/url_scanner_ex.re" state_before_val: start = YYCURSOR; -#line 802 "ext/standard/url_scanner_ex.c" +#line 839 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -837,44 +874,54 @@ state_before_val: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yych == ' ') goto yy37; - if (yych == '=') goto yy38; - ++YYCURSOR; -yy36: -#line 553 "ext/standard/url_scanner_ex.re" - { --YYCURSOR; goto state_next_arg_begin; } -#line 847 "ext/standard/url_scanner_ex.c" -yy37: + if (yych == ' ') goto yy39; + if (yych == '=') goto yy41; + goto yy43; +yy39: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ' ') goto yy41; - if (yych != '=') goto yy36; -yy38: + if (yych == ' ') goto yy46; + if (yych == '=') goto yy44; +yy40: +#line 551 "ext/standard/url_scanner_ex.re" + { --YYCURSOR; goto state_next_arg_begin; } +#line 888 "ext/standard/url_scanner_ex.c" +yy41: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy45; +yy42: +#line 550 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } +#line 896 "ext/standard/url_scanner_ex.c" +yy43: + yych = *++YYCURSOR; + goto yy40; +yy44: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy45: if (yybm[0+yych] & 128) { - goto yy38; + goto yy44; } -#line 552 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } -#line 861 "ext/standard/url_scanner_ex.c" -yy41: + goto yy42; +yy46: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if (yych == ' ') goto yy41; - if (yych == '=') goto yy38; + if (yych == ' ') goto yy46; + if (yych == '=') goto yy44; YYCURSOR = YYMARKER; - goto yy36; + goto yy40; } -#line 554 "ext/standard/url_scanner_ex.re" +#line 552 "ext/standard/url_scanner_ex.re" state_val: start = YYCURSOR; -#line 878 "ext/standard/url_scanner_ex.c" +#line 925 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -882,7 +929,7 @@ state_val: 224, 192, 192, 224, 224, 192, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, - 192, 224, 128, 224, 224, 224, 224, 64, + 192, 224, 64, 224, 224, 224, 224, 128, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 0, 224, @@ -913,69 +960,87 @@ state_val: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 32) { - goto yy46; + if (yych <= ' ') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy54; + if (yych <= '\n') goto yy56; + goto yy54; + } else { + if (yych <= '\r') goto yy56; + if (yych <= 0x1F) goto yy54; + goto yy56; + } + } else { + if (yych <= '&') { + if (yych != '"') goto yy54; + } else { + if (yych <= '\'') goto yy53; + if (yych == '>') goto yy56; + goto yy54; + } } - if (yych <= ' ') goto yy49; - if (yych <= '"') goto yy51; - if (yych <= '\'') goto yy52; - goto yy49; -yy46: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != '>') goto yy65; +yy52: +#line 561 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_next_arg_begin; } +#line 988 "ext/standard/url_scanner_ex.c" +yy53: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == '>') goto yy52; + goto yy60; +yy54: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy58; +yy55: +#line 560 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; } +#line 1000 "ext/standard/url_scanner_ex.c" +yy56: + yych = *++YYCURSOR; + goto yy52; +yy57: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy58: if (yybm[0+yych] & 32) { - goto yy46; + goto yy57; } -#line 562 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; } -#line 933 "ext/standard/url_scanner_ex.c" -yy49: - ++YYCURSOR; -yy50: -#line 563 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_next_arg_begin; } -#line 939 "ext/standard/url_scanner_ex.c" -yy51: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == '>') goto yy50; - goto yy54; -yy52: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == '>') goto yy50; - goto yy59; -yy53: + goto yy55; +yy59: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy54: +yy60: if (yybm[0+yych] & 64) { - goto yy53; + goto yy59; } - if (yych <= '"') goto yy56; -yy55: + if (yych <= '=') goto yy62; +yy61: YYCURSOR = YYMARKER; - goto yy50; -yy56: + goto yy52; +yy62: ++YYCURSOR; -#line 560 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } -#line 964 "ext/standard/url_scanner_ex.c" -yy58: +#line 559 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } +#line 1029 "ext/standard/url_scanner_ex.c" +yy64: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy59: +yy65: if (yybm[0+yych] & 128) { - goto yy58; + goto yy64; } - if (yych >= '(') goto yy55; + if (yych >= '>') goto yy61; ++YYCURSOR; -#line 561 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } -#line 977 "ext/standard/url_scanner_ex.c" +#line 558 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } +#line 1042 "ext/standard/url_scanner_ex.c" } -#line 564 "ext/standard/url_scanner_ex.re" +#line 562 "ext/standard/url_scanner_ex.re" stop: @@ -1103,7 +1168,7 @@ static inline void php_url_scanner_session_handler_impl(char *output, size_t out if (ZSTR_LEN(url_state->url_app.s) != 0) { *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0), url_state); - if (sizeof(uint32_t) < sizeof(size_t)) { + if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; } diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index 51a29b5..beb01c4 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -185,8 +185,6 @@ alphadash = ([a-zA-Z] | "-"); static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) { php_url *url_parts; - char *tmp; - size_t tmp_len; smart_str_0(url); /* FIXME: Bug #70480 php_url_parse_ex() crashes by processing chars exceed len */ url_parts = php_url_parse_ex(ZSTR_VAL(url->s), ZSTR_LEN(url->s)); @@ -199,21 +197,23 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st /* Check protocol. Only http/https is allowed. */ if (url_parts->scheme - && strcasecmp("http", url_parts->scheme) - && strcasecmp("https", url_parts->scheme)) { + && !zend_string_equals_literal_ci(url_parts->scheme, "http") + && !zend_string_equals_literal_ci(url_parts->scheme, "https")) { smart_str_append_smart_str(dest, url); php_url_free(url_parts); return; } /* Check host whitelist. If it's not listed, do nothing. */ - if (url_parts->host - && (tmp_len = strlen(url_parts->host)) - && (tmp = php_strtolower(url_parts->host, tmp_len)) - && !zend_hash_str_find(&BG(url_adapt_session_hosts_ht), tmp, tmp_len)) { - smart_str_append_smart_str(dest, url); - php_url_free(url_parts); - return; + if (url_parts->host) { + zend_string *tmp = zend_string_tolower(url_parts->host); + if (!zend_hash_exists(&BG(url_adapt_session_hosts_ht), tmp)) { + zend_string_release(tmp); + smart_str_append_smart_str(dest, url); + php_url_free(url_parts); + return; + } + zend_string_release(tmp); } /* @@ -232,32 +232,32 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->scheme) { - smart_str_appends(dest, url_parts->scheme); + smart_str_appends(dest, ZSTR_VAL(url_parts->scheme)); smart_str_appends(dest, "://"); } else if (*(ZSTR_VAL(url->s)) == '/' && *(ZSTR_VAL(url->s)+1) == '/') { smart_str_appends(dest, "//"); } if (url_parts->user) { - smart_str_appends(dest, url_parts->user); + smart_str_appends(dest, ZSTR_VAL(url_parts->user)); if (url_parts->pass) { - smart_str_appends(dest, url_parts->pass); + smart_str_appends(dest, ZSTR_VAL(url_parts->pass)); smart_str_appendc(dest, ':'); } smart_str_appendc(dest, '@'); } if (url_parts->host) { - smart_str_appends(dest, url_parts->host); + smart_str_appends(dest, ZSTR_VAL(url_parts->host)); } if (url_parts->port) { smart_str_appendc(dest, ':'); smart_str_append_unsigned(dest, (long)url_parts->port); } if (url_parts->path) { - smart_str_appends(dest, url_parts->path); + smart_str_appends(dest, ZSTR_VAL(url_parts->path)); } smart_str_appendc(dest, '?'); if (url_parts->query) { - smart_str_appends(dest, url_parts->query); + smart_str_appends(dest, ZSTR_VAL(url_parts->query)); smart_str_appends(dest, separator); smart_str_append_smart_str(dest, url_app); } else { @@ -265,7 +265,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->fragment) { smart_str_appendc(dest, '#'); - smart_str_appends(dest, url_parts->fragment); + smart_str_appends(dest, ZSTR_VAL(url_parts->fragment)); } php_url_free(url_parts); } @@ -386,8 +386,8 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) if (url_parts->scheme) { /* Only http/https should be handled. A bit hacky check this here, but saves a URL parse. */ - if (strcasecmp(url_parts->scheme, "http") && - strcasecmp(url_parts->scheme, "https")) { + if (!zend_string_equals_literal_ci(url_parts->scheme, "http") && + !zend_string_equals_literal_ci(url_parts->scheme, "https")) { php_url_free(url_parts); return FAILURE; } @@ -397,13 +397,11 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) return SUCCESS; } if (!zend_hash_num_elements(allowed_hosts) && - check_http_host(url_parts->host) == SUCCESS) { + check_http_host(ZSTR_VAL(url_parts->host)) == SUCCESS) { php_url_free(url_parts); return SUCCESS; } - if (!zend_hash_str_find(allowed_hosts, - url_parts->host, - strlen(url_parts->host))) { + if (!zend_hash_find(allowed_hosts, url_parts->host)) { php_url_free(url_parts); return FAILURE; }
diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 0d1152b..fa30e45 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -210,7 +210,7 @@ static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) return FAILURE; } - if (uri->scheme && !strncasecmp("file", uri->scheme, sizeof("file"))) { + if (uri->scheme && zend_string_equals_literal_ci(uri->scheme, "file")) { php_error_docref(NULL, E_WARNING, "Protocol 'file' disabled in cURL"); php_url_free(uri); return FAILURE; diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index c203adc..e0a858a 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -532,7 +532,8 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ RETURN_VALIDATION_FAILED } - if (url->scheme != NULL && (!strcasecmp(url->scheme, "http") || !strcasecmp(url->scheme, "https"))) { + if (url->scheme != NULL && + (zend_string_equals_literal_ci(url->scheme, "http") || zend_string_equals_literal_ci(url->scheme, "https"))) { char *e, *s, *t; size_t l; @@ -540,9 +541,9 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ goto bad_url; } - s = url->host; - l = strlen(s); - e = url->host + l; + s = ZSTR_VAL(url->host); + l = ZSTR_LEN(url->host); + e = s + l; t = e - 1; /* An IPv6 enclosed by square brackets is a valid hostname */ @@ -552,7 +553,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ } // Validate domain - if (!_php_filter_validate_domain(url->host, l, FILTER_FLAG_HOSTNAME)) { + if (!_php_filter_validate_domain(ZSTR_VAL(url->host), l, FILTER_FLAG_HOSTNAME)) { php_url_free(url); RETURN_VALIDATION_FAILED } @@ -561,7 +562,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(url->scheme, "mailto") && strcmp(url->scheme, "news") && strcmp(url->scheme, "file"))) || + (url->host == NULL && (strcmp(ZSTR_VAL(url->scheme), "mailto") && strcmp(ZSTR_VAL(url->scheme), "news") && strcmp(ZSTR_VAL(url->scheme), "file"))) || ((flags & FILTER_FLAG_PATH_REQUIRED) && url->path == NULL) || ((flags & FILTER_FLAG_QUERY_REQUIRED) && url->query == NULL) ) { bad_url: diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index fe7aeda..bb47f39 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2581,9 +2581,9 @@ static char *php_openssl_get_url_name(const char *resourcename, } if (url->host) { - const char * host = url->host; + const char * host = ZSTR_VAL(url->host); char * url_name = NULL; - size_t len = strlen(host); + size_t len = ZSTR_LEN(url->host); /* skip trailing dots */ while (len && host[len-1] == '.') { diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index cb95cdf..ce37a44 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -319,7 +319,7 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, /* we must have at the very least phar://alias.phar/ */ if (!resource->scheme || !resource->host || !resource->path) { if (resource->host && !resource->path) { - php_stream_wrapper_log_error(wrapper, options, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: no directory in \"%s\", must have at least phar://%s/ for root directory (always use full path to a new phar)", path, ZSTR_VAL(resource->host)); php_url_free(resource); return NULL; } @@ -328,22 +328,22 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, return NULL; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar url \"%s\"", path); return NULL; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - internal_file = resource->path + 1; /* strip leading "/" */ + internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar file \"%s\" is unknown", resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar file \"%s\" is unknown", ZSTR_VAL(resource->host)); } php_url_free(resource); return NULL; @@ -446,48 +446,48 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url_from); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - if ((e = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error, 1))) { + if ((e = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 2, &error, 1))) { /* directory exists, or is a subdirectory of an existing file */ if (e->is_temp_dir) { efree(e->filename); efree(e); } - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", directory already exists", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); php_url_free(resource); return 0; } if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - if (phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 0, &error, 1)) { + if (phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1, 0, &error, 1)) { /* entry exists as a file */ - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", file already exists", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); php_url_free(resource); return 0; } if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; @@ -500,14 +500,14 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo entry.is_zip = 1; } - entry.filename = estrdup(resource->path + 1); + entry.filename = estrdup(ZSTR_VAL(resource->path) + 1); if (phar->is_tar) { entry.is_tar = 1; entry.tar_type = TAR_DIR; } - entry.filename_len = strlen(resource->path + 1); + entry.filename_len = ZSTR_LEN(resource->path) - 1; php_url_free(resource); entry.is_dir = 1; entry.phar = phar; @@ -581,29 +581,29 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", resource->path+1, resource->host, error); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); php_url_free(resource); return 0; } - path_len = strlen(resource->path+1); + path_len = ZSTR_LEN(resource->path) - 1; - if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, path_len, 2, &error, 1))) { + if (!(entry = phar_get_entry_info_dir(phar, ZSTR_VAL(resource->path) + 1, path_len, 2, &error, 1))) { if (error) { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", resource->path+1, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", directory does not exist", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host)); } php_url_free(resource); return 0; @@ -615,7 +615,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options zend_hash_move_forward(&phar->manifest) ) { if (ZSTR_LEN(str_key) > path_len && - memcmp(ZSTR_VAL(str_key), resource->path+1, path_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource->path)+1, path_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[path_len])) { php_stream_wrapper_log_error(wrapper, options, "phar error: Directory not empty"); if (entry->is_temp_dir) { @@ -632,7 +632,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options zend_hash_move_forward(&phar->virtual_dirs)) { if (ZSTR_LEN(str_key) > path_len && - memcmp(ZSTR_VAL(str_key), resource->path+1, path_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource->path)+1, path_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[path_len])) { php_stream_wrapper_log_error(wrapper, options, "phar error: Directory not empty"); if (entry->is_temp_dir) { @@ -646,7 +646,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options } if (entry->is_temp_dir) { - zend_hash_str_del(&phar->virtual_dirs, resource->path+1, path_len); + zend_hash_str_del(&phar->virtual_dirs, ZSTR_VAL(resource->path)+1, path_len); efree(entry->filename); efree(entry); } else { diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 97e1dc6..65eabd9 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -84,19 +84,21 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const return NULL; } resource = ecalloc(1, sizeof(php_url)); - resource->scheme = estrndup("phar", 4); - resource->host = arch; + resource->scheme = zend_string_init("phar", 4, 0); + resource->host = zend_string_init(arch, arch_len, 0); + efree(arch); + resource->path = zend_string_init(entry, entry_len, 0); + efree(entry); - resource->path = entry; #if MBO_0 if (resource) { fprintf(stderr, "Alias: %s\n", alias); - fprintf(stderr, "Scheme: %s\n", resource->scheme); + fprintf(stderr, "Scheme: %s\n", ZSTR_VAL(resource->scheme)); /* fprintf(stderr, "User: %s\n", resource->user);*/ /* fprintf(stderr, "Pass: %s\n", resource->pass ? "***" : NULL);*/ - fprintf(stderr, "Host: %s\n", resource->host); + fprintf(stderr, "Host: %s\n", ZSTR_VAL(resource->host)); /* fprintf(stderr, "Port: %d\n", resource->port);*/ - fprintf(stderr, "Path: %s\n", resource->path); + fprintf(stderr, "Path: %s\n", ZSTR_VAL(resource->path)); /* fprintf(stderr, "Query: %s\n", resource->query);*/ /* fprintf(stderr, "Fragment: %s\n", resource->fragment);*/ } @@ -104,7 +106,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { phar_archive_data *pphar = NULL, *phar; - if (PHAR_G(request_init) && PHAR_G(phar_fname_map.u.flags) && NULL == (pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), arch, arch_len))) { + if (PHAR_G(request_init) && PHAR_G(phar_fname_map.u.flags) && NULL == (pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host))) { pphar = NULL; } if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) { @@ -114,7 +116,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const php_url_free(resource); return NULL; } - if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, 0, options, &phar, &error) == FAILURE) + if (phar_open_or_create_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, 0, options, &phar, &error) == FAILURE) { if (error) { if (!(options & PHP_STREAM_URL_STAT_QUIET)) { @@ -127,7 +129,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const } if (phar->is_persistent && FAILURE == phar_copy_on_write(&phar)) { if (error) { - spprintf(&error, 0, "Cannot open cached phar '%s' as writeable, copy on write failed", resource->host); + spprintf(&error, 0, "Cannot open cached phar '%s' as writeable, copy on write failed", ZSTR_VAL(resource->host)); if (!(options & PHP_STREAM_URL_STAT_QUIET)) { php_stream_wrapper_log_error(wrapper, options, "%s", error); } @@ -137,7 +139,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const return NULL; } } else { - if (phar_open_from_filename(resource->host, arch_len, NULL, 0, options, NULL, &error) == FAILURE) + if (phar_open_from_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, options, NULL, &error) == FAILURE) { if (error) { if (!(options & PHP_STREAM_URL_STAT_QUIET)) { @@ -179,24 +181,24 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha return NULL; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", path); return NULL; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); /* strip leading "/" */ - internal_file = estrdup(resource->path + 1); + internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { - if (NULL == (idata = phar_get_or_create_entry_data(resource->host, host_len, internal_file, strlen(internal_file), mode, 0, &error, 1))) { + if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), mode, 0, &error, 1))) { if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: file \"%s\" could not be created in phar \"%s\"", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: file \"%s\" could not be created in phar \"%s\"", internal_file, ZSTR_VAL(resource->host)); } efree(internal_file); php_url_free(resource); @@ -239,14 +241,14 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha } else { if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) { /* retrieve the stub */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, NULL)) { - php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", resource->host); + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, NULL)) { + php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", ZSTR_VAL(resource->host)); efree(internal_file); php_url_free(resource); return NULL; } if (phar->is_tar || phar->is_zip) { - if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) { goto idata_error; } efree(internal_file); @@ -284,13 +286,13 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha } } /* read-only access is allowed to magic files in .phar directory */ - if ((FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) { + if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) { idata_error: if (error) { php_stream_wrapper_log_error(wrapper, options, "%s", error); efree(error); } else { - php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" is not a file in phar \"%s\"", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" is not a file in phar \"%s\"", internal_file, ZSTR_VAL(resource->host)); } efree(internal_file); php_url_free(resource); @@ -569,17 +571,17 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f return FAILURE; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); return FAILURE; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - internal_file = resource->path + 1; /* strip leading "/" */ + internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */ /* find the phar in our trusty global hash indexed by alias (host of phar://blah.phar/file.whatever) */ - if (FAILURE == phar_get_archive(&phar, resource->host, host_len, NULL, 0, &error)) { + if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) { php_url_free(resource); if (error) { efree(error); @@ -679,16 +681,16 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int return 0; } - if (strcasecmp("phar", resource->scheme)) { + if (!zend_string_equals_literal_ci(resource->scheme, "phar")) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: not a phar stream url \"%s\"", url); return 0; } - host_len = strlen(resource->host); + host_len = ZSTR_LEN(resource->host); phar_request_initialize(); - pphar = zend_hash_str_find_ptr(&(PHAR_G(phar_fname_map)), resource->host, host_len); + pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host); if (PHAR_G(readonly) && (!pphar || !pphar->is_data)) { php_url_free(resource); php_stream_wrapper_log_error(wrapper, options, "phar error: write operations disabled by the php.ini setting phar.readonly"); @@ -696,9 +698,9 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int } /* need to copy to strip leading "/", will get touched again */ - internal_file = estrdup(resource->path + 1); - internal_file_len = strlen(internal_file); - if (FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, internal_file_len, "r", 0, &error, 1)) { + internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1); + internal_file_len = ZSTR_LEN(resource->path) - 1; + if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, internal_file_len, "r", 0, &error, 1)) { /* constraints of fp refcount were not met */ if (error) { php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error); @@ -715,7 +717,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int } if (idata->internal_file->fp_refcount > 1) { /* more than just our fp resource is open for this file */ - php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink", internal_file, resource->host); + php_stream_wrapper_log_error(wrapper, options, "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink", internal_file, ZSTR_VAL(resource->host)); efree(internal_file); php_url_free(resource); phar_entry_delref(idata); @@ -748,7 +750,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_from); return 0; } - if (SUCCESS != phar_get_archive(&pfrom, resource_from->host, strlen(resource_from->host), NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&pfrom, ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, &error)) { pfrom = NULL; if (error) { efree(error); @@ -765,7 +767,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_to); return 0; } - if (SUCCESS != phar_get_archive(&pto, resource_to->host, strlen(resource_to->host), NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&pto, ZSTR_VAL(resource_to->host), ZSTR_LEN(resource_to->host), NULL, 0, &error)) { if (error) { efree(error); } @@ -777,7 +779,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (strcmp(resource_from->host, resource_to->host)) { + if (!zend_string_equals(resource_from->host, resource_to->host)) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\", not within the same phar archive", url_from, url_to); @@ -799,23 +801,23 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (strcasecmp("phar", resource_from->scheme)) { + if (!zend_string_equals_literal_ci(resource_from->scheme, "phar")) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": not a phar stream url \"%s\"", url_from, url_to, url_from); return 0; } - if (strcasecmp("phar", resource_to->scheme)) { + if (!zend_string_equals_literal_ci(resource_to->scheme, "phar")) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": not a phar stream url \"%s\"", url_from, url_to, url_to); return 0; } - host_len = strlen(resource_from->host); + host_len = ZSTR_LEN(resource_from->host); - if (SUCCESS != phar_get_archive(&phar, resource_from->host, host_len, NULL, 0, &error)) { + if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": %s", url_from, url_to, error); @@ -830,7 +832,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from return 0; } - if (NULL != (entry = zend_hash_str_find_ptr(&(phar->manifest), resource_from->path+1, strlen(resource_from->path)-1))) { + if (NULL != (entry = zend_hash_str_find_ptr(&(phar->manifest), ZSTR_VAL(resource_from->path)+1, ZSTR_LEN(resource_from->path)-1))) { phar_entry_info new, *source; /* perform rename magic */ @@ -850,9 +852,9 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from source = entry; /* add to the manifest, and then store the pointer to the new guy in entry */ - entry = zend_hash_str_add_mem(&(phar->manifest), resource_to->path+1, strlen(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info)); + entry = zend_hash_str_add_mem(&(phar->manifest), ZSTR_VAL(resource_to->path)+1, ZSTR_LEN(resource_to->path)-1, (void **)&new, sizeof(phar_entry_info)); - entry->filename = estrdup(resource_to->path+1); + entry->filename = estrndup(ZSTR_VAL(resource_to->path)+1, ZSTR_LEN(resource_to->path)-1); if (FAILURE == phar_copy_entry_fp(source, entry, &error)) { php_url_free(resource_from); php_url_free(resource_to); @@ -866,7 +868,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from entry->filename_len = strlen(entry->filename); is_dir = entry->is_dir; } else { - is_dir = zend_hash_str_exists(&(phar->virtual_dirs), resource_from->path+1, strlen(resource_from->path)-1); + is_dir = zend_hash_str_exists(&(phar->virtual_dirs), ZSTR_VAL(resource_from->path)+1, ZSTR_LEN(resource_from->path)-1); if (!is_dir) { /* file does not exist */ php_url_free(resource_from); @@ -882,19 +884,19 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from Bucket *b; zend_string *str_key; zend_string *new_str_key; - uint32_t from_len = strlen(resource_from->path+1); - uint32_t to_len = strlen(resource_to->path+1); + uint32_t from_len = ZSTR_LEN(resource_from->path) - 1; + uint32_t to_len = ZSTR_LEN(resource_to->path) - 1; ZEND_HASH_FOREACH_BUCKET(&phar->manifest, b) { str_key = b->key; entry = Z_PTR(b->val); if (!entry->is_deleted && ZSTR_LEN(str_key) > from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && IS_SLASH(ZSTR_VAL(str_key)[from_len])) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; @@ -915,11 +917,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from ZEND_HASH_FOREACH_BUCKET(&phar->virtual_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && (ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; @@ -933,11 +935,11 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from ZEND_HASH_FOREACH_BUCKET(&phar->mounted_dirs, b) { str_key = b->key; if (ZSTR_LEN(str_key) >= from_len && - memcmp(ZSTR_VAL(str_key), resource_from->path+1, from_len) == 0 && + memcmp(ZSTR_VAL(str_key), ZSTR_VAL(resource_from->path)+1, from_len) == 0 && (ZSTR_LEN(str_key) == from_len || IS_SLASH(ZSTR_VAL(str_key)[from_len]))) { new_str_key = zend_string_alloc(ZSTR_LEN(str_key) + to_len - from_len, 0); - memcpy(ZSTR_VAL(new_str_key), resource_to->path + 1, to_len); + memcpy(ZSTR_VAL(new_str_key), ZSTR_VAL(resource_to->path) + 1, to_len); memcpy(ZSTR_VAL(new_str_key) + to_len, ZSTR_VAL(str_key) + from_len, ZSTR_LEN(str_key) - from_len); ZSTR_VAL(new_str_key)[ZSTR_LEN(new_str_key)] = 0; diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index c0b5f61..d8d8f95 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -179,7 +179,7 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph port = Z_LVAL_P(proxy_port); *use_proxy = 1; } else { - host = phpurl->host; + host = ZSTR_VAL(phpurl->host); port = phpurl->port; } if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_connection_timeout", sizeof("_connection_timeout")-1)) != NULL && @@ -243,18 +243,18 @@ static php_stream* http_connect(zval* this_ptr, php_url *phpurl, int use_ssl, ph /* Set peer_name or name verification will try to use the proxy server name */ if (!context || (tmp = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) { - ZVAL_STRING(&ssl_proxy_peer_name, phpurl->host); + ZVAL_STR_COPY(&ssl_proxy_peer_name, phpurl->host); php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name); zval_ptr_dtor(&ssl_proxy_peer_name); } smart_str_append_const(&soap_headers, "CONNECT "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); smart_str_append_const(&soap_headers, " HTTP/1.1\r\n"); smart_str_append_const(&soap_headers, "Host: "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); if (phpurl->port != 80) { smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); @@ -454,9 +454,9 @@ try_again: } use_ssl = 0; - if (phpurl->scheme != NULL && strcmp(phpurl->scheme, "https") == 0) { + if (phpurl->scheme != NULL && zend_string_equals_literal(phpurl->scheme, "https")) { use_ssl = 1; - } else if (phpurl->scheme == NULL || strcmp(phpurl->scheme, "http") != 0) { + } else if (phpurl->scheme == NULL || !zend_string_equals_literal(phpurl->scheme, "http")) { php_url_free(phpurl); if (request != buf) { zend_string_release(request); @@ -489,10 +489,10 @@ try_again: if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "httpurl", sizeof("httpurl")-1)) != NULL && (orig = (php_url *) zend_fetch_resource_ex(tmp, "httpurl", le_url)) != NULL && ((use_proxy && !use_ssl) || - (((use_ssl && orig->scheme != NULL && strcmp(orig->scheme, "https") == 0) || + (((use_ssl && orig->scheme != NULL && zend_string_equals_literal(orig->scheme, "https")) || (!use_ssl && orig->scheme == NULL) || - (!use_ssl && strcmp(orig->scheme, "https") != 0)) && - strcmp(orig->host, phpurl->host) == 0 && + (!use_ssl && !zend_string_equals_literal(orig->scheme, "https"))) && + strcmp(ZSTR_VAL(orig->host), ZSTR_VAL(phpurl->host)) == 0 && orig->port == phpurl->port))) { } else { php_stream_close(stream); @@ -553,24 +553,24 @@ try_again: smart_str_append_const(&soap_headers, "POST "); if (use_proxy && !use_ssl) { - smart_str_appends(&soap_headers, phpurl->scheme); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->scheme)); smart_str_append_const(&soap_headers, "://"); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); } if (phpurl->path) { - smart_str_appends(&soap_headers, phpurl->path); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path)); } else { smart_str_appendc(&soap_headers, '/'); } if (phpurl->query) { smart_str_appendc(&soap_headers, '?'); - smart_str_appends(&soap_headers, phpurl->query); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query)); } if (phpurl->fragment) { smart_str_appendc(&soap_headers, '#'); - smart_str_appends(&soap_headers, phpurl->fragment); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment)); } if (http_1_1) { smart_str_append_const(&soap_headers, " HTTP/1.1\r\n"); @@ -578,7 +578,7 @@ try_again: smart_str_append_const(&soap_headers, " HTTP/1.0\r\n"); } smart_str_append_const(&soap_headers, "Host: "); - smart_str_appends(&soap_headers, phpurl->host); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->host)); if (phpurl->port != (use_ssl?443:80)) { smart_str_appendc(&soap_headers, ':'); smart_str_append_unsigned(&soap_headers, phpurl->port); @@ -702,13 +702,13 @@ try_again: PHP_MD5Init(&md5ctx); PHP_MD5Update(&md5ctx, (unsigned char*)"POST:", sizeof("POST:")-1); if (phpurl->path) { - PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->path, strlen(phpurl->path)); + PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->path), ZSTR_LEN(phpurl->path)); } else { PHP_MD5Update(&md5ctx, (unsigned char*)"/", 1); } if (phpurl->query) { PHP_MD5Update(&md5ctx, (unsigned char*)"?", 1); - PHP_MD5Update(&md5ctx, (unsigned char*)phpurl->query, strlen(phpurl->query)); + PHP_MD5Update(&md5ctx, (unsigned char*)ZSTR_VAL(phpurl->query), ZSTR_LEN(phpurl->query)); } PHP_MD5Final(hash, &md5ctx); @@ -750,17 +750,17 @@ try_again: } smart_str_append_const(&soap_headers, "\", uri=\""); if (phpurl->path) { - smart_str_appends(&soap_headers, phpurl->path); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->path)); } else { smart_str_appendc(&soap_headers, '/'); } if (phpurl->query) { smart_str_appendc(&soap_headers, '?'); - smart_str_appends(&soap_headers, phpurl->query); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->query)); } if (phpurl->fragment) { smart_str_appendc(&soap_headers, '#'); - smart_str_appends(&soap_headers, phpurl->fragment); + smart_str_appends(&soap_headers, ZSTR_VAL(phpurl->fragment)); } if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "qop", sizeof("qop")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) { @@ -835,10 +835,10 @@ try_again: zval *tmp; if (((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 1)) == NULL || Z_TYPE_P(tmp) != IS_STRING || - strncmp(phpurl->path?phpurl->path:"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) && + strncmp(phpurl->path?ZSTR_VAL(phpurl->path):"/",Z_STRVAL_P(tmp),Z_STRLEN_P(tmp)) == 0) && ((tmp = zend_hash_index_find(Z_ARRVAL_P(data), 2)) == NULL || Z_TYPE_P(tmp) != IS_STRING || - in_domain(phpurl->host,Z_STRVAL_P(tmp))) && + in_domain(ZSTR_VAL(phpurl->host),Z_STRVAL_P(tmp))) && (use_ssl || (tmp = zend_hash_index_find(Z_ARRVAL_P(data), 3)) == NULL)) { smart_str_append(&soap_headers, key); smart_str_appendc(&soap_headers, '='); @@ -1006,14 +1006,15 @@ try_again: } } if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 1)) { - char *t = phpurl->path?phpurl->path:"/"; + char *t = phpurl->path?ZSTR_VAL(phpurl->path):"/"; char *c = strrchr(t, '/'); if (c) { add_index_stringl(&zcookie, 1, t, c-t); } } if (!zend_hash_index_exists(Z_ARRVAL(zcookie), 2)) { - add_index_string(&zcookie, 2, phpurl->host); + add_index_str(&zcookie, 2, phpurl->host); + GC_REFCOUNT(phpurl->host)++; } zend_symtable_update(Z_ARRVAL_P(cookies), name.s, &zcookie); @@ -1108,26 +1109,27 @@ try_again: zend_string_release(http_body); efree(loc); if (new_url->scheme == NULL && new_url->path != NULL) { - new_url->scheme = phpurl->scheme ? estrdup(phpurl->scheme) : NULL; - new_url->host = phpurl->host ? estrdup(phpurl->host) : NULL; + new_url->scheme = phpurl->scheme ? zend_string_copy(phpurl->scheme) : NULL; + new_url->host = phpurl->host ? zend_string_copy(phpurl->host) : NULL; new_url->port = phpurl->port; - if (new_url->path && new_url->path[0] != '/') { + if (new_url->path && ZSTR_VAL(new_url->path)[0] != '/') { if (phpurl->path) { - char *t = phpurl->path; + char *t = ZSTR_VAL(phpurl->path); char *p = strrchr(t, '/'); if (p) { - char *s = emalloc((p - t) + strlen(new_url->path) + 2); - strncpy(s, t, (p - t) + 1); - s[(p - t) + 1] = 0; - strcat(s, new_url->path); - efree(new_url->path); + zend_string *s = zend_string_alloc((p - t) + ZSTR_LEN(new_url->path) + 2, 0); + strncpy(ZSTR_VAL(s), t, (p - t) + 1); + ZSTR_VAL(s)[(p - t) + 1] = 0; + strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path)); + zend_string_release(new_url->path); new_url->path = s; } } else { - char *s = emalloc(strlen(new_url->path) + 2); - s[0] = '/'; s[1] = 0; - strcat(s, new_url->path); - efree(new_url->path); + zend_string *s = zend_string_alloc(ZSTR_LEN(new_url->path) + 2, 0); + ZSTR_VAL(s)[0] = '/'; + ZSTR_VAL(s)[1] = 0; + strcat(ZSTR_VAL(s), ZSTR_VAL(new_url->path)); + zend_string_release(new_url->path); new_url->path = s; } } @@ -1202,13 +1204,13 @@ try_again: add_property_zval_ex(this_ptr, "_digest", sizeof("_digest")-1, &digest); *new_url = *phpurl; - if (phpurl->scheme) phpurl->scheme = estrdup(phpurl->scheme); - if (phpurl->user) phpurl->user = estrdup(phpurl->user); - if (phpurl->pass) phpurl->pass = estrdup(phpurl->pass); - if (phpurl->host) phpurl->host = estrdup(phpurl->host); - if (phpurl->path) phpurl->path = estrdup(phpurl->path); - if (phpurl->query) phpurl->query = estrdup(phpurl->query); - if (phpurl->fragment) phpurl->fragment = estrdup(phpurl->fragment); + if (phpurl->scheme) phpurl->scheme = zend_string_copy(phpurl->scheme); + if (phpurl->user) phpurl->user = zend_string_copy(phpurl->user); + if (phpurl->pass) phpurl->pass = zend_string_copy(phpurl->pass); + if (phpurl->host) phpurl->host = zend_string_copy(phpurl->host); + if (phpurl->path) phpurl->path = zend_string_copy(phpurl->path); + if (phpurl->query) phpurl->query = zend_string_copy(phpurl->query); + if (phpurl->fragment) phpurl->fragment = zend_string_copy(phpurl->fragment); phpurl = new_url; efree(auth); diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index d54f2f6..b548ddd 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -135,7 +135,7 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char { php_stream *stream = NULL, *reuseid = NULL; php_url *resource = NULL; - int result, use_ssl, use_ssl_on_data = 0, tmp_len; + int result, use_ssl, use_ssl_on_data = 0; char tmp_line[512]; char *transport; int transport_len; @@ -148,13 +148,13 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char return NULL; } - use_ssl = resource->scheme && (strlen(resource->scheme) > 3) && resource->scheme[3] == 's'; + use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 3) && ZSTR_VAL(resource->scheme)[3] == 's'; /* use port 21 if one wasn't specified */ if (resource->port == 0) resource->port = 21; - transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", resource->host, resource->port); + transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", ZSTR_VAL(resource->host), resource->port); stream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL); efree(transport); if (stream == NULL) { @@ -245,11 +245,11 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char /* send the user name */ if (resource->user != NULL) { - tmp_len = (int)php_raw_url_decode(resource->user, (int)strlen(resource->user)); + ZSTR_LEN(resource->user) = php_raw_url_decode(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user)); - PHP_FTP_CNTRL_CHK(resource->user, tmp_len, "Invalid login %s") + PHP_FTP_CNTRL_CHK(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user), "Invalid login %s") - php_stream_printf(stream, "USER %s\r\n", resource->user); + php_stream_printf(stream, "USER %s\r\n", ZSTR_VAL(resource->user)); } else { php_stream_write_string(stream, "USER anonymous\r\n"); } @@ -262,11 +262,11 @@ static php_stream *php_ftp_fopen_connect(php_stream_wrapper *wrapper, const char php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, tmp_line, 0); if (resource->pass != NULL) { - tmp_len = (int)php_raw_url_decode(resource->pass, (int)strlen(resource->pass)); + ZSTR_LEN(resource->pass) = php_raw_url_decode(ZSTR_VAL(resource->pass), ZSTR_LEN(resource->pass)); - PHP_FTP_CNTRL_CHK(resource->pass, tmp_len, "Invalid password %s") + PHP_FTP_CNTRL_CHK(resource->pass, ZSTR_LEN(resource->pass), "Invalid password %s") - php_stream_printf(stream, "PASS %s\r\n", resource->pass); + php_stream_printf(stream, "PASS %s\r\n", ZSTR_VAL(resource->pass)); } else { /* if the user has configured who they are, send that as the password */ @@ -548,11 +548,11 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa /* Append */ memcpy(tmp_line, "APPE", sizeof("APPE")); } - php_stream_printf(stream, "%s %s\r\n", tmp_line, (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "%s %s\r\n", tmp_line, (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); /* open the data channel */ if (hoststart == NULL) { - hoststart = resource->host; + hoststart = ZSTR_VAL(resource->host); } transport_len = (int)spprintf(&transport, 0, "tcp://%s:%d", hoststart, portno); datastream = php_stream_xport_create(transport, transport_len, REPORT_ERRORS, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, NULL, NULL, context, NULL, NULL); @@ -719,7 +719,7 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat /* open the data channel */ if (hoststart == NULL) { - hoststart = resource->host; + hoststart = ZSTR_VAL(resource->host); } datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0); @@ -727,7 +727,7 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat goto opendir_errexit; } - php_stream_printf(stream, "NLST %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "NLST %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result != 150 && result != 125) { @@ -792,7 +792,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, } ssb->sb.st_mode = 0644; /* FTP won't give us a valid mode, so approximate one based on being readable */ - php_stream_printf(stream, "CWD %s\r\n", (resource->path != NULL ? resource->path : "/")); /* If we can CWD to it, it's a directory (maybe a link, but we can't tell) */ + php_stream_printf(stream, "CWD %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); /* If we can CWD to it, it's a directory (maybe a link, but we can't tell) */ result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { ssb->sb.st_mode |= S_IFREG; @@ -808,7 +808,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, goto stat_errexit; } - php_stream_printf(stream, "SIZE %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "SIZE %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { /* Failure either means it doesn't exist @@ -823,7 +823,7 @@ static int php_stream_ftp_url_stat(php_stream_wrapper *wrapper, const char *url, ssb->sb.st_size = atoi(tmp_line + 4); } - php_stream_printf(stream, "MDTM %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "MDTM %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result == 213) { char *p = tmp_line + 4; @@ -922,7 +922,7 @@ static int php_stream_ftp_unlink(php_stream_wrapper *wrapper, const char *url, i } /* Attempt to delete the file */ - php_stream_printf(stream, "DELE %s\r\n", (resource->path != NULL ? resource->path : "/")); + php_stream_printf(stream, "DELE %s\r\n", (resource->path != NULL ? ZSTR_VAL(resource->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { @@ -965,10 +965,10 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr !resource_to || !resource_from->scheme || !resource_to->scheme || - strcmp(resource_from->scheme, resource_to->scheme) || + !zend_string_equals(resource_from->scheme, resource_to->scheme) || !resource_from->host || !resource_to->host || - strcmp(resource_from->host, resource_to->host) || + !zend_string_equals(resource_from->host, resource_to->host) || (resource_from->port != resource_to->port && resource_from->port * resource_to->port != 0 && resource_from->port + resource_to->port != 21) || @@ -980,13 +980,13 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr stream = php_ftp_fopen_connect(wrapper, url_from, "r", 0, NULL, context, NULL, NULL, NULL, NULL); if (!stream) { if (options & REPORT_ERRORS) { - php_error_docref(NULL, E_WARNING, "Unable to connect to %s", resource_from->host); + php_error_docref(NULL, E_WARNING, "Unable to connect to %s", ZSTR_VAL(resource_from->host)); } goto rename_errexit; } /* Rename FROM */ - php_stream_printf(stream, "RNFR %s\r\n", (resource_from->path != NULL ? resource_from->path : "/")); + php_stream_printf(stream, "RNFR %s\r\n", (resource_from->path != NULL ? ZSTR_VAL(resource_from->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 300 || result > 399) { @@ -997,7 +997,7 @@ static int php_stream_ftp_rename(php_stream_wrapper *wrapper, const char *url_fr } /* Rename TO */ - php_stream_printf(stream, "RNTO %s\r\n", (resource_to->path != NULL ? resource_to->path : "/")); + php_stream_printf(stream, "RNTO %s\r\n", (resource_to->path != NULL ? ZSTR_VAL(resource_to->path) : "/")); result = GET_FTP_RESULT(stream); if (result < 200 || result > 299) { @@ -1051,14 +1051,14 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in } if (!recursive) { - php_stream_printf(stream, "MKD %s\r\n", resource->path); + php_stream_printf(stream, "MKD %s\r\n", ZSTR_VAL(resource->path)); result = GET_FTP_RESULT(stream); } else { /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ char *p, *e, *buf; - buf = estrdup(resource->path); - e = buf + strlen(buf); + buf = estrndup(ZSTR_VAL(resource->path), ZSTR_LEN(resource->path)); + e = buf + ZSTR_LEN(resource->path); /* find a top level directory we need to create */ while ((p = strrchr(buf, '/'))) { @@ -1071,7 +1071,7 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char *url, in } } if (p == buf) { - php_stream_printf(stream, "MKD %s\r\n", resource->path); + php_stream_printf(stream, "MKD %s\r\n", ZSTR_VAL(resource->path)); result = GET_FTP_RESULT(stream); } else { php_stream_printf(stream, "MKD %s\r\n", buf); diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 7208404..f0881c2 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -152,7 +152,8 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, return NULL; } - if (strncasecmp(resource->scheme, "http", sizeof("http")) && strncasecmp(resource->scheme, "https", sizeof("https"))) { + if (!zend_string_equals_literal_ci(resource->scheme, "http") && + !zend_string_equals_literal_ci(resource->scheme, "https")) { if (!context || (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "proxy")) == NULL || Z_TYPE_P(tmpzval) != IS_STRING || @@ -176,7 +177,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, return NULL; } - use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's'; + use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) && ZSTR_VAL(resource->scheme)[4] == 's'; /* choose default ports */ if (use_ssl && resource->port == 0) resource->port = 443; @@ -191,7 +192,7 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, transport_len = Z_STRLEN_P(tmpzval); transport_string = estrndup(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval)); } else { - transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port); + transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", ZSTR_VAL(resource->host), resource->port); } } @@ -234,13 +235,13 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, /* Set peer_name or name verification will try to use the proxy server name */ if (!context || (tmpzval = php_stream_context_get_option(context, "ssl", "peer_name")) == NULL) { - ZVAL_STRING(&ssl_proxy_peer_name, resource->host); + ZVAL_STR_COPY(&ssl_proxy_peer_name, resource->host); php_stream_context_set_option(PHP_STREAM_CONTEXT(stream), "ssl", "peer_name", &ssl_proxy_peer_name); zval_ptr_dtor(&ssl_proxy_peer_name); } smart_str_appendl(&header, "CONNECT ", sizeof("CONNECT ")-1); - smart_str_appends(&header, resource->host); + smart_str_appends(&header, ZSTR_VAL(resource->host)); smart_str_appendc(&header, ':'); smart_str_append_unsigned(&header, resource->port); smart_str_appendl(&header, " HTTP/1.0\r\n", sizeof(" HTTP/1.0\r\n")-1); @@ -388,8 +389,8 @@ finish: /* Send the traditional /path/to/file?query_string */ /* file */ - if (resource->path && *resource->path) { - smart_str_appends(&req_buf, resource->path); + if (resource->path && ZSTR_LEN(resource->path)) { + smart_str_appends(&req_buf, ZSTR_VAL(resource->path)); } else { smart_str_appendc(&req_buf, '/'); } @@ -397,7 +398,7 @@ finish: /* query string */ if (resource->query) { smart_str_appendc(&req_buf, '?'); - smart_str_appends(&req_buf, resource->query); + smart_str_appends(&req_buf, ZSTR_VAL(resource->query)); } } @@ -531,15 +532,15 @@ finish: zend_string *stmp; /* decode the strings first */ - php_url_decode(resource->user, strlen(resource->user)); + php_url_decode(ZSTR_VAL(resource->user), ZSTR_LEN(resource->user)); - strcpy(scratch, resource->user); + strcpy(scratch, ZSTR_VAL(resource->user)); strcat(scratch, ":"); /* Note: password is optional! */ if (resource->pass) { - php_url_decode(resource->pass, strlen(resource->pass)); - strcat(scratch, resource->pass); + php_url_decode(ZSTR_VAL(resource->pass), ZSTR_LEN(resource->pass)); + strcat(scratch, ZSTR_VAL(resource->pass)); } stmp = php_base64_encode((unsigned char*)scratch, strlen(scratch)); @@ -564,7 +565,7 @@ finish: /* Send Host: header so name-based virtual hosts work */ if ((have_header & HTTP_HEADER_HOST) == 0) { smart_str_appends(&req_buf, "Host: "); - smart_str_appends(&req_buf, resource->host); + smart_str_appends(&req_buf, ZSTR_VAL(resource->host)); if ((use_ssl && resource->port != 443 && resource->port != 0) || (!use_ssl && resource->port != 80 && resource->port != 0)) { smart_str_appendc(&req_buf, ':'); @@ -855,21 +856,24 @@ finish: { if (*location != '/') { if (*(location+1) != '\0' && resource->path) { - char *s = strrchr(resource->path, '/'); + char *s = strrchr(ZSTR_VAL(resource->path), '/'); if (!s) { - s = resource->path; - if (!s[0]) { - efree(s); - s = resource->path = estrdup("/"); + s = ZSTR_VAL(resource->path); + if (!ZSTR_LEN(resource->path)) { + zend_string_release(resource->path); + resource->path = zend_string_init("/", 1, 0); + s = ZSTR_VAL(resource->path); } else { *s = '/'; } } s[1] = '\0'; - if (resource->path && *(resource->path) == '/' && *(resource->path + 1) == '\0') { - snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", resource->path, location); + if (resource->path && + ZSTR_VAL(resource->path)[0] == '/' && + ZSTR_VAL(resource->path)[1] == '\0') { + snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", ZSTR_VAL(resource->path), location); } else { - snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", resource->path, location); + snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", ZSTR_VAL(resource->path), location); } } else { snprintf(loc_path, sizeof(loc_path) - 1, "/%s", location); @@ -878,9 +882,9 @@ finish: strlcpy(loc_path, location, sizeof(loc_path)); } if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->host, resource->port, loc_path); + snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", ZSTR_VAL(resource->scheme), ZSTR_VAL(resource->host), resource->port, loc_path); } else { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->host, loc_path); + snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", ZSTR_VAL(resource->scheme), ZSTR_VAL(resource->host), loc_path); } } else { strlcpy(new_path, location, sizeof(new_path)); @@ -896,9 +900,8 @@ finish: #define CHECK_FOR_CNTRL_CHARS(val) { \ if (val) { \ unsigned char *s, *e; \ - size_t l; \ - l = php_url_decode(val, strlen(val)); \ - s = (unsigned char*)val; e = s + l; \ + ZSTR_LEN(val) = php_url_decode(ZSTR_VAL(val), ZSTR_LEN(val)); \ + s = (unsigned char*)ZSTR_VAL(val); e = s + ZSTR_LEN(val); \ while (s < e) { \ if (iscntrl(*s)) { \ php_stream_wrapper_log_error(wrapper, options, "Invalid redirect URL! %s", new_path); \ @@ -910,9 +913,9 @@ finish: } /* check for control characters in login, password & path */ if (strncasecmp(new_path, "http://", sizeof("http://") - 1) || strncasecmp(new_path, "https://", sizeof("https://") - 1)) { - CHECK_FOR_CNTRL_CHARS(resource->user) - CHECK_FOR_CNTRL_CHARS(resource->pass) - CHECK_FOR_CNTRL_CHARS(resource->path) + CHECK_FOR_CNTRL_CHARS(resource->user); + CHECK_FOR_CNTRL_CHARS(resource->pass); + CHECK_FOR_CNTRL_CHARS(resource->path); } stream = php_stream_url_wrap_http_ex( wrapper, new_path, mode, options, opened_path, context, diff --git a/ext/standard/url.c b/ext/standard/url.c index a3a19a2..e909eee 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -42,19 +42,19 @@ PHPAPI void php_url_free(php_url *theurl) { if (theurl->scheme) - efree(theurl->scheme); + zend_string_release(theurl->scheme); if (theurl->user) - efree(theurl->user); + zend_string_release(theurl->user); if (theurl->pass) - efree(theurl->pass); + zend_string_release(theurl->pass); if (theurl->host) - efree(theurl->host); + zend_string_release(theurl->host); if (theurl->path) - efree(theurl->path); + zend_string_release(theurl->path); if (theurl->query) - efree(theurl->query); + zend_string_release(theurl->query); if (theurl->fragment) - efree(theurl->fragment); + zend_string_release(theurl->fragment); efree(theurl); } /* }}} */ @@ -124,8 +124,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) } if (e + 1 == ue) { /* only scheme is available */ - ret->scheme = estrndup(s, (e - s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e - s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); return ret; } @@ -146,18 +146,18 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) goto parse_port; } - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); s = e + 1; goto just_path; } else { - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars_ex(ret->scheme, (e - s)); + ret->scheme = zend_string_init(s, (e-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->scheme), ZSTR_LEN(ret->scheme)); if (e + 2 < ue && *(e + 2) == '/') { s = e + 3; - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { + if (zend_string_equals_literal_ci(ret->scheme, "file")) { if (e + 3 < ue && *(e + 3) == '/') { /* support windows drive letters as in: file:///c:/somedir/file.txt @@ -193,13 +193,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) s += 2; } } else { - if (ret->scheme) efree(ret->scheme); - efree(ret); + php_url_free(ret); return NULL; } } else if (p == pp && pp == ue) { - if (ret->scheme) efree(ret->scheme); - efree(ret); + php_url_free(ret); return NULL; } else if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; @@ -228,15 +226,15 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) /* check for login and password */ if ((p = zend_memrchr(s, '@', (e-s)))) { if ((pp = memchr(s, ':', (p-s)))) { - ret->user = estrndup(s, (pp-s)); - php_replace_controlchars_ex(ret->user, (pp - s)); + ret->user = zend_string_init(s, (pp-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); pp++; - ret->pass = estrndup(pp, (p-pp)); - php_replace_controlchars_ex(ret->pass, (p-pp)); + ret->pass = zend_string_init(pp, (p-pp), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->pass), ZSTR_LEN(ret->pass)); } else { - ret->user = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->user, (p-s)); + ret->user = zend_string_init(s, (p-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->user), ZSTR_LEN(ret->user)); } s = p + 1; @@ -256,10 +254,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (!ret->port) { p++; if (e-p > 5) { /* port cannot be longer then 5 characters */ - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } else if (e - p > 0) { zend_long port; @@ -269,10 +264,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (port > 0 && port <= 65535) { ret->port = (unsigned short)port; } else { - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } } @@ -284,15 +276,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) /* check if we have a valid host, if we don't reject the string as url */ if ((p-s) < 1) { - if (ret->scheme) efree(ret->scheme); - if (ret->user) efree(ret->user); - if (ret->pass) efree(ret->pass); - efree(ret); + php_url_free(ret); return NULL; } - ret->host = estrndup(s, (p-s)); - php_replace_controlchars_ex(ret->host, (p - s)); + ret->host = zend_string_init(s, (p-s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->host), ZSTR_LEN(ret->host)); if (e == ue) { return ret; @@ -307,8 +296,8 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p) { p++; if (p < e) { - ret->fragment = estrndup(p, (e - p)); - php_replace_controlchars_ex(ret->fragment, (e - p)); + ret->fragment = zend_string_init(p, (e - p), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->fragment), ZSTR_LEN(ret->fragment)); } e = p-1; } @@ -317,15 +306,15 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length) if (p) { p++; if (p < e) { - ret->query = estrndup(p, (e - p)); - php_replace_controlchars_ex(ret->query, (e - p)); + ret->query = zend_string_init(p, (e - p), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->query), ZSTR_LEN(ret->query)); } e = p-1; } if (s < e || s == ue) { - ret->path = estrndup(s, (e - s)); - php_replace_controlchars_ex(ret->path, (e - s)); + ret->path = zend_string_init(s, (e - s), 0); + php_replace_controlchars_ex(ZSTR_VAL(ret->path), ZSTR_LEN(ret->path)); } return ret; @@ -357,28 +346,28 @@ PHP_FUNCTION(parse_url) if (key > -1) { switch (key) { case PHP_URL_SCHEME: - if (resource->scheme != NULL) RETVAL_STRING(resource->scheme); + if (resource->scheme != NULL) RETVAL_STR_COPY(resource->scheme); break; case PHP_URL_HOST: - if (resource->host != NULL) RETVAL_STRING(resource->host); + if (resource->host != NULL) RETVAL_STR_COPY(resource->host); break; case PHP_URL_PORT: if (resource->port != 0) RETVAL_LONG(resource->port); break; case PHP_URL_USER: - if (resource->user != NULL) RETVAL_STRING(resource->user); + if (resource->user != NULL) RETVAL_STR_COPY(resource->user); break; case PHP_URL_PASS: - if (resource->pass != NULL) RETVAL_STRING(resource->pass); + if (resource->pass != NULL) RETVAL_STR_COPY(resource->pass); break; case PHP_URL_PATH: - if (resource->path != NULL) RETVAL_STRING(resource->path); + if (resource->path != NULL) RETVAL_STR_COPY(resource->path); break; case PHP_URL_QUERY: - if (resource->query != NULL) RETVAL_STRING(resource->query); + if (resource->query != NULL) RETVAL_STR_COPY(resource->query); break; case PHP_URL_FRAGMENT: - if (resource->fragment != NULL) RETVAL_STRING(resource->fragment); + if (resource->fragment != NULL) RETVAL_STR_COPY(resource->fragment); break; default: php_error_docref(NULL, E_WARNING, "Invalid URL component identifier " ZEND_LONG_FMT, key); @@ -392,11 +381,11 @@ PHP_FUNCTION(parse_url) /* add the various elements to the array */ if (resource->scheme != NULL) { - ZVAL_STRING(&tmp, resource->scheme); + ZVAL_STR_COPY(&tmp, resource->scheme); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_SCHEME), &tmp); } if (resource->host != NULL) { - ZVAL_STRING(&tmp, resource->host); + ZVAL_STR_COPY(&tmp, resource->host); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_HOST), &tmp); } if (resource->port != 0) { @@ -404,23 +393,23 @@ PHP_FUNCTION(parse_url) zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PORT), &tmp); } if (resource->user != NULL) { - ZVAL_STRING(&tmp, resource->user); + ZVAL_STR_COPY(&tmp, resource->user); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_USER), &tmp); } if (resource->pass != NULL) { - ZVAL_STRING(&tmp, resource->pass); + ZVAL_STR_COPY(&tmp, resource->pass); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PASS), &tmp); } if (resource->path != NULL) { - ZVAL_STRING(&tmp, resource->path); + ZVAL_STR_COPY(&tmp, resource->path); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_PATH), &tmp); } if (resource->query != NULL) { - ZVAL_STRING(&tmp, resource->query); + ZVAL_STR_COPY(&tmp, resource->query); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_QUERY), &tmp); } if (resource->fragment != NULL) { - ZVAL_STRING(&tmp, resource->fragment); + ZVAL_STR_COPY(&tmp, resource->fragment); zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_FRAGMENT), &tmp); } done: diff --git a/ext/standard/url.h b/ext/standard/url.h index 7a2f20e..8c4e63e 100644 --- a/ext/standard/url.h +++ b/ext/standard/url.h @@ -21,14 +21,14 @@ #define URL_H typedef struct php_url { - char *scheme; - char *user; - char *pass; - char *host; + zend_string *scheme; + zend_string *user; + zend_string *pass; + zend_string *host; unsigned short port; - char *path; - char *query; - char *fragment; + zend_string *path; + zend_string *query; + zend_string *fragment; } php_url; PHPAPI void php_url_free(php_url *theurl); diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index 484d5d9..af8a378 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.16 */ +/* Generated by re2c 0.13.5 */ #line 1 "ext/standard/url_scanner_ex.re" /* +----------------------------------------------------------------------+ @@ -182,8 +182,6 @@ PHP_INI_END() static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) { php_url *url_parts; - char *tmp; - size_t tmp_len; smart_str_0(url); /* FIXME: Bug #70480 php_url_parse_ex() crashes by processing chars exceed len */ url_parts = php_url_parse_ex(ZSTR_VAL(url->s), ZSTR_LEN(url->s)); @@ -196,21 +194,23 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st /* Check protocol. Only http/https is allowed. */ if (url_parts->scheme - && strcasecmp("http", url_parts->scheme) - && strcasecmp("https", url_parts->scheme)) { + && !zend_string_equals_literal_ci(url_parts->scheme, "http") + && !zend_string_equals_literal_ci(url_parts->scheme, "https")) { smart_str_append_smart_str(dest, url); php_url_free(url_parts); return; } /* Check host whitelist. If it's not listed, do nothing. */ - if (url_parts->host - && (tmp_len = strlen(url_parts->host)) - && (tmp = php_strtolower(url_parts->host, tmp_len)) - && !zend_hash_str_find(&BG(url_adapt_session_hosts_ht), tmp, tmp_len)) { - smart_str_append_smart_str(dest, url); - php_url_free(url_parts); - return; + if (url_parts->host) { + zend_string *tmp = zend_string_tolower(url_parts->host); + if (!zend_hash_exists(&BG(url_adapt_session_hosts_ht), tmp)) { + zend_string_release(tmp); + smart_str_append_smart_str(dest, url); + php_url_free(url_parts); + return; + } + zend_string_release(tmp); } /* @@ -229,32 +229,32 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->scheme) { - smart_str_appends(dest, url_parts->scheme); + smart_str_appends(dest, ZSTR_VAL(url_parts->scheme)); smart_str_appends(dest, "://"); } else if (*(ZSTR_VAL(url->s)) == '/' && *(ZSTR_VAL(url->s)+1) == '/') { smart_str_appends(dest, "//"); } if (url_parts->user) { - smart_str_appends(dest, url_parts->user); + smart_str_appends(dest, ZSTR_VAL(url_parts->user)); if (url_parts->pass) { - smart_str_appends(dest, url_parts->pass); + smart_str_appends(dest, ZSTR_VAL(url_parts->pass)); smart_str_appendc(dest, ':'); } smart_str_appendc(dest, '@'); } if (url_parts->host) { - smart_str_appends(dest, url_parts->host); + smart_str_appends(dest, ZSTR_VAL(url_parts->host)); } if (url_parts->port) { smart_str_appendc(dest, ':'); smart_str_append_unsigned(dest, (long)url_parts->port); } if (url_parts->path) { - smart_str_appends(dest, url_parts->path); + smart_str_appends(dest, ZSTR_VAL(url_parts->path)); } smart_str_appendc(dest, '?'); if (url_parts->query) { - smart_str_appends(dest, url_parts->query); + smart_str_appends(dest, ZSTR_VAL(url_parts->query)); smart_str_appends(dest, separator); smart_str_append_smart_str(dest, url_app); } else { @@ -262,7 +262,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->fragment) { smart_str_appendc(dest, '#'); - smart_str_appends(dest, url_parts->fragment); + smart_str_appends(dest, ZSTR_VAL(url_parts->fragment)); } php_url_free(url_parts); } @@ -383,8 +383,8 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) if (url_parts->scheme) { /* Only http/https should be handled. A bit hacky check this here, but saves a URL parse. */ - if (strcasecmp(url_parts->scheme, "http") && - strcasecmp(url_parts->scheme, "https")) { + if (!zend_string_equals_literal_ci(url_parts->scheme, "http") && + !zend_string_equals_literal_ci(url_parts->scheme, "https")) { php_url_free(url_parts); return FAILURE; } @@ -394,13 +394,11 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) return SUCCESS; } if (!zend_hash_num_elements(allowed_hosts) && - check_http_host(url_parts->host) == SUCCESS) { + check_http_host(ZSTR_VAL(url_parts->host)) == SUCCESS) { php_url_free(url_parts); return SUCCESS; } - if (!zend_hash_str_find(allowed_hosts, - url_parts->host, - strlen(url_parts->host))) { + if (!zend_hash_find(allowed_hosts, url_parts->host)) { php_url_free(url_parts); return FAILURE; } @@ -513,7 +511,7 @@ state_plain_begin: state_plain: start = YYCURSOR; -#line 517 "ext/standard/url_scanner_ex.c" +#line 515 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -550,35 +548,34 @@ state_plain: 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, }; + if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yybm[0+yych] & 128) { - goto yy2; + goto yy4; } - goto yy5; -yy2: + ++YYCURSOR; +#line 517 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } +#line 561 "ext/standard/url_scanner_ex.c" +yy4: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yybm[0+yych] & 128) { - goto yy2; + goto yy4; } -#line 520 "ext/standard/url_scanner_ex.re" +#line 518 "ext/standard/url_scanner_ex.re" { passthru(STD_ARGS); goto state_plain; } -#line 569 "ext/standard/url_scanner_ex.c" -yy5: - ++YYCURSOR; -#line 519 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } -#line 574 "ext/standard/url_scanner_ex.c" +#line 571 "ext/standard/url_scanner_ex.c" } -#line 521 "ext/standard/url_scanner_ex.re" +#line 519 "ext/standard/url_scanner_ex.re" state_tag: start = YYCURSOR; -#line 582 "ext/standard/url_scanner_ex.c" +#line 579 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -615,27 +612,39 @@ state_tag: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy11; + if (yych <= '@') { + if (yych != ':') goto yy11; + } else { + if (yych <= 'Z') goto yy9; + if (yych <= '`') goto yy11; + if (yych >= '{') goto yy11; } +yy9: ++YYCURSOR; -#line 527 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_plain_begin; } -#line 627 "ext/standard/url_scanner_ex.c" + yych = *YYCURSOR; + goto yy14; +yy10: +#line 524 "ext/standard/url_scanner_ex.re" + { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } +#line 632 "ext/standard/url_scanner_ex.c" yy11: ++YYCURSOR; +#line 525 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_plain_begin; } +#line 637 "ext/standard/url_scanner_ex.c" +yy13: + ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy14: if (yybm[0+yych] & 128) { - goto yy11; + goto yy13; } -#line 526 "ext/standard/url_scanner_ex.re" - { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } -#line 637 "ext/standard/url_scanner_ex.c" + goto yy10; } -#line 528 "ext/standard/url_scanner_ex.re" +#line 526 "ext/standard/url_scanner_ex.re" state_next_arg_begin: @@ -644,7 +653,7 @@ state_next_arg_begin: state_next_arg: start = YYCURSOR; -#line 648 "ext/standard/url_scanner_ex.c" +#line 657 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -683,57 +692,78 @@ state_next_arg: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy18; - } - if (yych <= '>') { - if (yych == '/') goto yy21; - if (yych >= '>') goto yy22; + if (yych <= '.') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy25; + if (yych <= '\v') goto yy21; + goto yy25; + } else { + if (yych <= '\r') goto yy21; + if (yych == ' ') goto yy21; + goto yy25; + } } else { - if (yych <= 'Z') { - if (yych >= 'A') goto yy24; + if (yych <= '@') { + if (yych <= '/') goto yy17; + if (yych == '>') goto yy19; + goto yy25; } else { - if (yych <= '`') goto yy16; - if (yych <= 'z') goto yy24; + if (yych <= 'Z') goto yy23; + if (yych <= '`') goto yy25; + if (yych <= 'z') goto yy23; + goto yy25; } } -yy16: - ++YYCURSOR; yy17: -#line 539 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_plain_begin; } -#line 706 "ext/standard/url_scanner_ex.c" -yy18: ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy18; - } + if ((yych = *YYCURSOR) == '>') goto yy28; +yy18: #line 537 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_next_arg; } -#line 716 "ext/standard/url_scanner_ex.c" + { passthru(STD_ARGS); goto state_plain_begin; } +#line 724 "ext/standard/url_scanner_ex.c" +yy19: + ++YYCURSOR; +yy20: +#line 534 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } +#line 730 "ext/standard/url_scanner_ex.c" yy21: - yych = *++YYCURSOR; - if (yych != '>') goto yy17; + ++YYCURSOR; + yych = *YYCURSOR; + goto yy27; yy22: +#line 535 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_next_arg; } +#line 738 "ext/standard/url_scanner_ex.c" +yy23: ++YYCURSOR; #line 536 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } -#line 724 "ext/standard/url_scanner_ex.c" -yy24: - ++YYCURSOR; -#line 538 "ext/standard/url_scanner_ex.re" { --YYCURSOR; STATE = STATE_ARG; goto state_arg; } -#line 729 "ext/standard/url_scanner_ex.c" +#line 743 "ext/standard/url_scanner_ex.c" +yy25: + yych = *++YYCURSOR; + goto yy18; +yy26: + ++YYCURSOR; + if (YYLIMIT <= YYCURSOR) YYFILL(1); + yych = *YYCURSOR; +yy27: + if (yybm[0+yych] & 128) { + goto yy26; + } + goto yy22; +yy28: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy20; } -#line 540 "ext/standard/url_scanner_ex.re" +#line 538 "ext/standard/url_scanner_ex.re" state_arg: start = YYCURSOR; -#line 737 "ext/standard/url_scanner_ex.c" +#line 767 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -770,35 +800,42 @@ state_arg: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - if (YYLIMIT <= YYCURSOR) YYFILL(1); + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yych <= '@') goto yy28; - if (yych <= 'Z') goto yy30; - if (yych <= '`') goto yy28; - if (yych <= 'z') goto yy30; -yy28: + if (yych <= '@') goto yy33; + if (yych <= 'Z') goto yy31; + if (yych <= '`') goto yy33; + if (yych >= '{') goto yy33; +yy31: ++YYCURSOR; -#line 546 "ext/standard/url_scanner_ex.re" + yych = *YYCURSOR; + goto yy36; +yy32: +#line 543 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } +#line 817 "ext/standard/url_scanner_ex.c" +yy33: + ++YYCURSOR; +#line 544 "ext/standard/url_scanner_ex.re" { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; } -#line 784 "ext/standard/url_scanner_ex.c" -yy30: +#line 822 "ext/standard/url_scanner_ex.c" +yy35: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy36: if (yybm[0+yych] & 128) { - goto yy30; + goto yy35; } -#line 545 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } -#line 794 "ext/standard/url_scanner_ex.c" + goto yy32; } -#line 547 "ext/standard/url_scanner_ex.re" +#line 545 "ext/standard/url_scanner_ex.re" state_before_val: start = YYCURSOR; -#line 802 "ext/standard/url_scanner_ex.c" +#line 839 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -837,44 +874,54 @@ state_before_val: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yych == ' ') goto yy37; - if (yych == '=') goto yy38; - ++YYCURSOR; -yy36: -#line 553 "ext/standard/url_scanner_ex.re" - { --YYCURSOR; goto state_next_arg_begin; } -#line 847 "ext/standard/url_scanner_ex.c" -yy37: + if (yych == ' ') goto yy39; + if (yych == '=') goto yy41; + goto yy43; +yy39: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ' ') goto yy41; - if (yych != '=') goto yy36; -yy38: + if (yych == ' ') goto yy46; + if (yych == '=') goto yy44; +yy40: +#line 551 "ext/standard/url_scanner_ex.re" + { --YYCURSOR; goto state_next_arg_begin; } +#line 888 "ext/standard/url_scanner_ex.c" +yy41: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy45; +yy42: +#line 550 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } +#line 896 "ext/standard/url_scanner_ex.c" +yy43: + yych = *++YYCURSOR; + goto yy40; +yy44: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy45: if (yybm[0+yych] & 128) { - goto yy38; + goto yy44; } -#line 552 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } -#line 861 "ext/standard/url_scanner_ex.c" -yy41: + goto yy42; +yy46: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; - if (yych == ' ') goto yy41; - if (yych == '=') goto yy38; + if (yych == ' ') goto yy46; + if (yych == '=') goto yy44; YYCURSOR = YYMARKER; - goto yy36; + goto yy40; } -#line 554 "ext/standard/url_scanner_ex.re" +#line 552 "ext/standard/url_scanner_ex.re" state_val: start = YYCURSOR; -#line 878 "ext/standard/url_scanner_ex.c" +#line 925 "ext/standard/url_scanner_ex.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@ -882,7 +929,7 @@ state_val: 224, 192, 192, 224, 224, 192, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, - 192, 224, 128, 224, 224, 224, 224, 64, + 192, 224, 64, 224, 224, 224, 224, 128, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 0, 224, @@ -913,69 +960,87 @@ state_val: }; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; - if (yybm[0+yych] & 32) { - goto yy46; + if (yych <= ' ') { + if (yych <= '\f') { + if (yych <= 0x08) goto yy54; + if (yych <= '\n') goto yy56; + goto yy54; + } else { + if (yych <= '\r') goto yy56; + if (yych <= 0x1F) goto yy54; + goto yy56; + } + } else { + if (yych <= '&') { + if (yych != '"') goto yy54; + } else { + if (yych <= '\'') goto yy53; + if (yych == '>') goto yy56; + goto yy54; + } } - if (yych <= ' ') goto yy49; - if (yych <= '"') goto yy51; - if (yych <= '\'') goto yy52; - goto yy49; -yy46: + yych = *(YYMARKER = ++YYCURSOR); + if (yych != '>') goto yy65; +yy52: +#line 561 "ext/standard/url_scanner_ex.re" + { passthru(STD_ARGS); goto state_next_arg_begin; } +#line 988 "ext/standard/url_scanner_ex.c" +yy53: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == '>') goto yy52; + goto yy60; +yy54: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy58; +yy55: +#line 560 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; } +#line 1000 "ext/standard/url_scanner_ex.c" +yy56: + yych = *++YYCURSOR; + goto yy52; +yy57: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; +yy58: if (yybm[0+yych] & 32) { - goto yy46; + goto yy57; } -#line 562 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; } -#line 933 "ext/standard/url_scanner_ex.c" -yy49: - ++YYCURSOR; -yy50: -#line 563 "ext/standard/url_scanner_ex.re" - { passthru(STD_ARGS); goto state_next_arg_begin; } -#line 939 "ext/standard/url_scanner_ex.c" -yy51: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == '>') goto yy50; - goto yy54; -yy52: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == '>') goto yy50; - goto yy59; -yy53: + goto yy55; +yy59: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy54: +yy60: if (yybm[0+yych] & 64) { - goto yy53; + goto yy59; } - if (yych <= '"') goto yy56; -yy55: + if (yych <= '=') goto yy62; +yy61: YYCURSOR = YYMARKER; - goto yy50; -yy56: + goto yy52; +yy62: ++YYCURSOR; -#line 560 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } -#line 964 "ext/standard/url_scanner_ex.c" -yy58: +#line 559 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } +#line 1029 "ext/standard/url_scanner_ex.c" +yy64: ++YYCURSOR; if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy59: +yy65: if (yybm[0+yych] & 128) { - goto yy58; + goto yy64; } - if (yych >= '(') goto yy55; + if (yych >= '>') goto yy61; ++YYCURSOR; -#line 561 "ext/standard/url_scanner_ex.re" - { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } -#line 977 "ext/standard/url_scanner_ex.c" +#line 558 "ext/standard/url_scanner_ex.re" + { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } +#line 1042 "ext/standard/url_scanner_ex.c" } -#line 564 "ext/standard/url_scanner_ex.re" +#line 562 "ext/standard/url_scanner_ex.re" stop: @@ -1103,7 +1168,7 @@ static inline void php_url_scanner_session_handler_impl(char *output, size_t out if (ZSTR_LEN(url_state->url_app.s) != 0) { *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0), url_state); - if (sizeof(uint32_t) < sizeof(size_t)) { + if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; } diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index 51a29b5..beb01c4 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -185,8 +185,6 @@ alphadash = ([a-zA-Z] | "-"); static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) { php_url *url_parts; - char *tmp; - size_t tmp_len; smart_str_0(url); /* FIXME: Bug #70480 php_url_parse_ex() crashes by processing chars exceed len */ url_parts = php_url_parse_ex(ZSTR_VAL(url->s), ZSTR_LEN(url->s)); @@ -199,21 +197,23 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st /* Check protocol. Only http/https is allowed. */ if (url_parts->scheme - && strcasecmp("http", url_parts->scheme) - && strcasecmp("https", url_parts->scheme)) { + && !zend_string_equals_literal_ci(url_parts->scheme, "http") + && !zend_string_equals_literal_ci(url_parts->scheme, "https")) { smart_str_append_smart_str(dest, url); php_url_free(url_parts); return; } /* Check host whitelist. If it's not listed, do nothing. */ - if (url_parts->host - && (tmp_len = strlen(url_parts->host)) - && (tmp = php_strtolower(url_parts->host, tmp_len)) - && !zend_hash_str_find(&BG(url_adapt_session_hosts_ht), tmp, tmp_len)) { - smart_str_append_smart_str(dest, url); - php_url_free(url_parts); - return; + if (url_parts->host) { + zend_string *tmp = zend_string_tolower(url_parts->host); + if (!zend_hash_exists(&BG(url_adapt_session_hosts_ht), tmp)) { + zend_string_release(tmp); + smart_str_append_smart_str(dest, url); + php_url_free(url_parts); + return; + } + zend_string_release(tmp); } /* @@ -232,32 +232,32 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->scheme) { - smart_str_appends(dest, url_parts->scheme); + smart_str_appends(dest, ZSTR_VAL(url_parts->scheme)); smart_str_appends(dest, "://"); } else if (*(ZSTR_VAL(url->s)) == '/' && *(ZSTR_VAL(url->s)+1) == '/') { smart_str_appends(dest, "//"); } if (url_parts->user) { - smart_str_appends(dest, url_parts->user); + smart_str_appends(dest, ZSTR_VAL(url_parts->user)); if (url_parts->pass) { - smart_str_appends(dest, url_parts->pass); + smart_str_appends(dest, ZSTR_VAL(url_parts->pass)); smart_str_appendc(dest, ':'); } smart_str_appendc(dest, '@'); } if (url_parts->host) { - smart_str_appends(dest, url_parts->host); + smart_str_appends(dest, ZSTR_VAL(url_parts->host)); } if (url_parts->port) { smart_str_appendc(dest, ':'); smart_str_append_unsigned(dest, (long)url_parts->port); } if (url_parts->path) { - smart_str_appends(dest, url_parts->path); + smart_str_appends(dest, ZSTR_VAL(url_parts->path)); } smart_str_appendc(dest, '?'); if (url_parts->query) { - smart_str_appends(dest, url_parts->query); + smart_str_appends(dest, ZSTR_VAL(url_parts->query)); smart_str_appends(dest, separator); smart_str_append_smart_str(dest, url_app); } else { @@ -265,7 +265,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st } if (url_parts->fragment) { smart_str_appendc(dest, '#'); - smart_str_appends(dest, url_parts->fragment); + smart_str_appends(dest, ZSTR_VAL(url_parts->fragment)); } php_url_free(url_parts); } @@ -386,8 +386,8 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) if (url_parts->scheme) { /* Only http/https should be handled. A bit hacky check this here, but saves a URL parse. */ - if (strcasecmp(url_parts->scheme, "http") && - strcasecmp(url_parts->scheme, "https")) { + if (!zend_string_equals_literal_ci(url_parts->scheme, "http") && + !zend_string_equals_literal_ci(url_parts->scheme, "https")) { php_url_free(url_parts); return FAILURE; } @@ -397,13 +397,11 @@ static int check_host_whitelist(url_adapt_state_ex_t *ctx) return SUCCESS; } if (!zend_hash_num_elements(allowed_hosts) && - check_http_host(url_parts->host) == SUCCESS) { + check_http_host(ZSTR_VAL(url_parts->host)) == SUCCESS) { php_url_free(url_parts); return SUCCESS; } - if (!zend_hash_str_find(allowed_hosts, - url_parts->host, - strlen(url_parts->host))) { + if (!zend_hash_find(allowed_hosts, url_parts->host)) { php_url_free(url_parts); return FAILURE; }