When using a literal IPv6 address as hostname, it can contain a Zone ID especially in the case of link-local addresses. Sending this to the server in the Host header is not useful to the server and in some cases servers refuse such requests. To prevent any such issues, strip the Zone ID from the address if it's an IPv6 address. This also removes it for the Cookies lookup. Based on a patch by: Daniel N Pettersson <danielnp@axis.com> (cherry picked from commit 5cb6d2221a6d4c07453b6c301ecfcaed48402680) Signed-off-by: Marvin Scholz <epirat07@gmail.com>
Unified · Split
| @@ -24,6 +24,7 @@ · 23 unmodified lines | |||
| 24 | #include "config.h" | 24 | #include "config.h" |
| 25 | #include "config_components.h" | 25 | #include "config_components.h" |
| 26 | 26 | ||
| 27 | #include <string.h> | ||
| 27 | #include <time.h> | 28 | #include <time.h> |
| 28 | #if CONFIG_ZLIB | 29 | #if CONFIG_ZLIB |
| 29 | #include <zlib.h> | 30 | #include <zlib.h> |
| @@ -214,7 +215,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 184 unmodified lines | |||
| 214 | const char *path, *proxy_path, *lower_proto = "tcp", *local_path; | 215 | const char *path, *proxy_path, *lower_proto = "tcp", *local_path; |
| 215 | char *env_http_proxy, *env_no_proxy; | 216 | char *env_http_proxy, *env_no_proxy; |
| 216 | char *hashmark; | 217 | char *hashmark; |
| 217 | char hostname[1024], hoststr[1024], proto[10]; | 218 | char hostname[1024], hoststr[1024], proto[10], tmp_host[1024]; |
| 218 | char auth[1024], proxyauth[1024] = ""; | 219 | char auth[1024], proxyauth[1024] = ""; |
| 219 | char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1]; | 220 | char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1]; |
| 220 | char buf[1024], urlbuf[MAX_URL_SIZE]; | 221 | char buf[1024], urlbuf[MAX_URL_SIZE]; |
| @@ -224,7 +225,14 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 3 unmodified lines | |||
| 224 | av_url_split(proto, sizeof(proto), auth, sizeof(auth), | 225 | av_url_split(proto, sizeof(proto), auth, sizeof(auth), |
| 225 | hostname, sizeof(hostname), &port, | 226 | hostname, sizeof(hostname), &port, |
| 226 | path1, sizeof(path1), s->location); | 227 | path1, sizeof(path1), s->location); |
| 227 | ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); | 228 | |
| 229 | av_strlcpy(tmp_host, hostname, sizeof(tmp_host)); | ||
| 230 | // In case of an IPv6 address, we need to strip the Zone ID, | ||
| 231 | // if any. We do it at the first % sign, as percent encoding | ||
| 232 | // can be used in the Zone ID itself. | ||
| 233 | if (strchr(tmp_host, ':')) | ||
| 234 | tmp_host[strcspn(tmp_host, "%")] = '\0'; | ||
| 235 | ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, tmp_host, port, NULL); | ||
| 228 | 236 | ||
| 229 | env_http_proxy = getenv_utf8("http_proxy"); | 237 | env_http_proxy = getenv_utf8("http_proxy"); |
| 230 | proxy_path = s->http_proxy ? s->http_proxy : env_http_proxy; | 238 | proxy_path = s->http_proxy ? s->http_proxy : env_http_proxy; |