X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_url.c;h=efa9116e4b7a8d300b660717a6981e988a0d05d5;hp=40ed57ec8c9fb43fe92ac6fb5c3fd7c578f0a49f;hb=305ac2f007710b684d96b05f33964b4f6a4e3e4d;hpb=1421b2b78469a66ebe3cd2958a608de9a036bca9 diff --git a/php_http_url.c b/php_http_url.c index 40ed57e..efa9116 100644 --- a/php_http_url.c +++ b/php_http_url.c @@ -92,7 +92,9 @@ static php_url *php_http_url_from_env(php_url *url TSRMLS_DC) if ((((zhost = php_http_env_get_server_var(ZEND_STRL("HTTP_HOST"), 1 TSRMLS_CC)) || (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_NAME"), 1 TSRMLS_CC)) || (zhost = php_http_env_get_server_var(ZEND_STRL("SERVER_ADDR"), 1 TSRMLS_CC)))) && Z_STRLEN_P(zhost)) { - url->host = estrndup(Z_STRVAL_P(zhost), Z_STRLEN_P(zhost)); + size_t stop_at = strspn(Z_STRVAL_P(zhost), "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-."); + + url->host = estrndup(Z_STRVAL_P(zhost), stop_at); } else { url->host = localhostname(); } @@ -222,7 +224,8 @@ PHP_HTTP_API void php_http_url(int flags, const php_url *old_url, const php_url STR_SET(url->path, path); } /* replace directory references if path is not a single slash */ - if (url->path[0] && (url->path[0] != '/' || url->path[1])) { + if ((flags & PHP_HTTP_URL_SANITIZE_PATH) + && url->path[0] && (url->path[0] != '/' || url->path[1])) { char *ptr, *end = url->path + strlen(url->path) + 1; for (ptr = strchr(url->path, '/'); ptr; ptr = strchr(ptr, '/')) { @@ -466,8 +469,14 @@ PHP_HTTP_BEGIN_ARGS(mod, 1) PHP_HTTP_ARG_VAL(flags, 0) PHP_HTTP_END_ARGS; -zend_class_entry *php_http_url_class_entry; -zend_function_entry php_http_url_method_entry[] = { +static zend_class_entry *php_http_url_class_entry; + +zend_class_entry *php_http_url_get_class_entry(void) +{ + return php_http_url_class_entry; +} + +static zend_function_entry php_http_url_method_entry[] = { PHP_HTTP_URL_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_HTTP_URL_ME(mod, ZEND_ACC_PUBLIC) PHP_HTTP_URL_ME(toString, ZEND_ACC_PUBLIC) @@ -478,12 +487,12 @@ zend_function_entry php_http_url_method_entry[] = { PHP_METHOD(HttpUrl, __construct) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { zval *new_url = NULL, *old_url = NULL; long flags = PHP_HTTP_URL_FROM_ENV; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags)) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { php_url *res_purl, *new_purl = NULL, *old_purl = NULL; if (new_url) { @@ -613,7 +622,7 @@ PHP_METHOD(HttpUrl, toArray) PHP_MINIT_FUNCTION(http_url) { - PHP_HTTP_REGISTER_CLASS(http, Url, http_url, php_http_object_class_entry, 0); + PHP_HTTP_REGISTER_CLASS(http, Url, http_url, php_http_object_get_class_entry(), 0); zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC); zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC); @@ -636,6 +645,7 @@ PHP_MINIT_FUNCTION(http_url) zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_FRAGMENT"), PHP_HTTP_URL_STRIP_FRAGMENT TSRMLS_CC); zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("STRIP_ALL"), PHP_HTTP_URL_STRIP_ALL TSRMLS_CC); zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("FROM_ENV"), PHP_HTTP_URL_FROM_ENV TSRMLS_CC); + zend_declare_class_constant_long(php_http_url_class_entry, ZEND_STRL("SANITIZE_PATH"), PHP_HTTP_URL_SANITIZE_PATH TSRMLS_CC); return SUCCESS; }