History

avformat/http: Handle IPv6 Zone ID in hostname

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>

Marvin Scholz committed 1 year ago

Commit 45fcd551 parent 558994b1 file · +10 −2Browse files

Showing the changes to libavformat (1 of 1 file). Show all

Unified · Split

libavformat/http.c+10−2
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include "config.h"
2525 #include "config_components.h"
2626
27+#include <string.h>
2728 #include <time.h>
2829 #if CONFIG_ZLIB
2930 #include <zlib.h>
@@ -214,7 +215,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 184 unmodified lines
214215 const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
215216 char *env_http_proxy, *env_no_proxy;
216217 char *hashmark;
217− char hostname[1024], hoststr[1024], proto[10];
218+ char hostname[1024], hoststr[1024], proto[10], tmp_host[1024];
218219 char auth[1024], proxyauth[1024] = "";
219220 char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1];
220221 char buf[1024], urlbuf[MAX_URL_SIZE];
@@ -224,7 +225,14 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 3 unmodified lines
224225 av_url_split(proto, sizeof(proto), auth, sizeof(auth),
225226 hostname, sizeof(hostname), &port,
226227 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);
228236
229237 env_http_proxy = getenv_utf8("http_proxy");
230238 proxy_path = s->http_proxy ? s->http_proxy : env_http_proxy;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t