From patchwork Sat Feb 8 21:18:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17718 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D8D2644B7C6 for ; Sat, 8 Feb 2020 23:18:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B274E68AFEB; Sat, 8 Feb 2020 23:18:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08DB368AFEB for ; Sat, 8 Feb 2020 23:18:30 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id E6169E3B91; Sat, 8 Feb 2020 22:18:29 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bz5HrjUJSrEB; Sat, 8 Feb 2020 22:18:28 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 0ECEAE3B07; Sat, 8 Feb 2020 22:18:28 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:12 +0100 Message-Id: <20200208211823.31345-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH 01/12] avformat/tests/url: make format more readable X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/tests/url.c | 3 ++- tests/ref/fate/url | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c index 1623179128..11ed5bb0b7 100644 --- a/libavformat/tests/url.c +++ b/libavformat/tests/url.c @@ -24,7 +24,7 @@ static void test(const char *base, const char *rel) { char buf[200], buf2[200]; ff_make_absolute_url(buf, sizeof(buf), base, rel); - printf("%s\n", buf); + printf("%50s %-20s => %s\n", base, rel, buf); if (base) { /* Test in-buffer replacement */ snprintf(buf2, sizeof(buf2), "%s", base); @@ -38,6 +38,7 @@ static void test(const char *base, const char *rel) int main(void) { + printf("Testing ff_make_absolute_url:\n"); test(NULL, "baz"); test("/foo/bar", "baz"); test("/foo/bar", "../baz"); diff --git a/tests/ref/fate/url b/tests/ref/fate/url index 1a6051ee0f..b5deba88ae 100644 --- a/tests/ref/fate/url +++ b/tests/ref/fate/url @@ -1,13 +1,14 @@ -baz -/foo/baz -/baz -/baz -http://server/foo/baz -http://server/foo/baz -http://server/baz -http://server/baz -http://server/baz -https://other/url -http://server/baz -http://server/foo/bar?someparam -http://other/url +Testing ff_make_absolute_url: + (null) baz => baz + /foo/bar baz => /foo/baz + /foo/bar ../baz => /baz + /foo/bar /baz => /baz + http://server/foo/ baz => http://server/foo/baz + http://server/foo/bar baz => http://server/foo/baz + http://server/foo/ ../baz => http://server/baz + http://server/foo/bar/123 ../../baz => http://server/baz + http://server/foo/bar/123 /baz => http://server/baz + http://server/foo/bar/123 https://other/url => https://other/url + http://server/foo/bar?param=value/with/slashes /baz => http://server/baz + http://server/foo/bar?param&otherparam ?someparam => http://server/foo/bar?someparam + http://server/foo/bar //other/url => http://other/url From patchwork Sat Feb 8 21:18:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17719 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B378444B7C6 for ; Sat, 8 Feb 2020 23:18:39 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9DC1568B03E; Sat, 8 Feb 2020 23:18:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A4AE68B01A for ; Sat, 8 Feb 2020 23:18:33 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5C25FE3925; Sat, 8 Feb 2020 22:18:33 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zzPx9h0eR09l; Sat, 8 Feb 2020 22:18:31 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id BA78BE3ABE; Sat, 8 Feb 2020 22:18:31 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:13 +0100 Message-Id: <20200208211823.31345-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 02/12] avformat/tests/url: add av_url_split tests X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/tests/url.c | 24 ++++++++++++++++++++++++ tests/ref/fate/url | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c index 11ed5bb0b7..d99876f02c 100644 --- a/libavformat/tests/url.c +++ b/libavformat/tests/url.c @@ -19,6 +19,7 @@ */ #include "libavformat/url.h" +#include "libavformat/avformat.h" static void test(const char *base, const char *rel) { @@ -36,6 +37,18 @@ static void test(const char *base, const char *rel) } } +static void test2(const char *url) +{ + char proto[64]; + char auth[256]; + char host[256]; + char path[256]; + int port=-1; + + av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host), &port, path, sizeof(path), url); + printf("%-60s => %-15s %-15s %-15s %5d %s\n", url, proto, auth, host, port, path); +} + int main(void) { printf("Testing ff_make_absolute_url:\n"); @@ -52,5 +65,16 @@ int main(void) test("http://server/foo/bar?param=value/with/slashes", "/baz"); test("http://server/foo/bar?param&otherparam", "?someparam"); test("http://server/foo/bar", "//other/url"); + + printf("\nTesting av_url_split:\n"); + test2("/foo/bar"); + test2("http://server/foo/"); + test2("http://example.com/foo/bar"); + test2("http://user:pass@localhost:8080/foo/bar/123"); + test2("http://server/foo/bar?param=value/with/slashes"); + test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8"); + test2("ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg"); + test2("https://key.dns.com?key_id=2&model_id=12345&&access_key="); + return 0; } diff --git a/tests/ref/fate/url b/tests/ref/fate/url index b5deba88ae..8212c1131b 100644 --- a/tests/ref/fate/url +++ b/tests/ref/fate/url @@ -12,3 +12,13 @@ Testing ff_make_absolute_url: http://server/foo/bar?param=value/with/slashes /baz => http://server/baz http://server/foo/bar?param&otherparam ?someparam => http://server/foo/bar?someparam http://server/foo/bar //other/url => http://other/url + +Testing av_url_split: +/foo/bar => -1 /foo/bar +http://server/foo/ => http server -1 /foo/ +http://example.com/foo/bar => http example.com -1 /foo/bar +http://user:pass@localhost:8080/foo/bar/123 => http user:pass localhost 8080 /foo/bar/123 +http://server/foo/bar?param=value/with/slashes => http server -1 /foo/bar?param=value/with/slashes +https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8 => https 1l-lh.a.net -1 /i/1LIVE_HDS@179577/master.m3u8 +ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg => ftp u:p%2B%2F2 ftp.pbt.com -1 /ExportHD.mpg +https://key.dns.com?key_id=2&model_id=12345&&access_key= => https key.dns.com -1 ?key_id=2&model_id=12345&&access_key= From patchwork Sat Feb 8 21:18:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17720 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A3DFA44B7C6 for ; Sat, 8 Feb 2020 23:18:59 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8E41268B042; Sat, 8 Feb 2020 23:18:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0F4068B02E for ; Sat, 8 Feb 2020 23:18:53 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id B8AB5E3925; Sat, 8 Feb 2020 22:18:53 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xYJc6FzZ3vOi; Sat, 8 Feb 2020 22:18:51 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 50449E3ABE; Sat, 8 Feb 2020 22:18:51 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:14 +0100 Message-Id: <20200208211823.31345-3-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 03/12] avformat/utils: make av_url_split search for hashmark as well to separate hostname X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" RFC 3986 states that the generic syntax uses the slash ("/"), question mark ("?"), and number sign ("#") characters to delimit components that are significant to the generic parser's hierarchical interpretation of an identifier. Signed-off-by: Marton Balint --- libavformat/tests/url.c | 1 + libavformat/utils.c | 14 +++----------- tests/ref/fate/url | 1 + 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c index d99876f02c..5e484fd428 100644 --- a/libavformat/tests/url.c +++ b/libavformat/tests/url.c @@ -75,6 +75,7 @@ int main(void) test2("https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8"); test2("ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg"); test2("https://key.dns.com?key_id=2&model_id=12345&&access_key="); + test2("http://example.com#tag"); return 0; } diff --git a/libavformat/utils.c b/libavformat/utils.c index e22ca7cab8..6897e98e97 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -4779,7 +4779,7 @@ void av_url_split(char *proto, int proto_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url) { - const char *p, *ls, *ls2, *at, *at2, *col, *brk; + const char *p, *ls, *at, *at2, *col, *brk; if (port_ptr) *port_ptr = -1; @@ -4807,16 +4807,8 @@ void av_url_split(char *proto, int proto_size, } /* separate path from hostname */ - ls = strchr(p, '/'); - ls2 = strchr(p, '?'); - if (!ls) - ls = ls2; - else if (ls && ls2) - ls = FFMIN(ls, ls2); - if (ls) - av_strlcpy(path, ls, path_size); - else - ls = &p[strlen(p)]; // XXX + ls = p + strcspn(p, "/?#"); + av_strlcpy(path, ls, path_size); /* the rest is hostname, use that to parse auth/port */ if (ls != p) { diff --git a/tests/ref/fate/url b/tests/ref/fate/url index 8212c1131b..980b2ce1f9 100644 --- a/tests/ref/fate/url +++ b/tests/ref/fate/url @@ -22,3 +22,4 @@ http://server/foo/bar?param=value/with/slashes => http https://1l-lh.a.net/i/1LIVE_HDS@179577/master.m3u8 => https 1l-lh.a.net -1 /i/1LIVE_HDS@179577/master.m3u8 ftp://u:p%2B%2F2@ftp.pbt.com/ExportHD.mpg => ftp u:p%2B%2F2 ftp.pbt.com -1 /ExportHD.mpg https://key.dns.com?key_id=2&model_id=12345&&access_key= => https key.dns.com -1 ?key_id=2&model_id=12345&&access_key= +http://example.com#tag => http example.com -1 #tag From patchwork Sat Feb 8 21:18:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17729 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a05:6214:1865:0:0:0:0 with SMTP id eh5csp972297qvb; Sat, 8 Feb 2020 13:19:11 -0800 (PST) X-Google-Smtp-Source: APXvYqxbi70d5Q5c3NXyOA+1ys1xmHWR42q/dE4bMnWpMTYmVcsYhZbZyjTeP0aK5S4cHVIGAGyC X-Received: by 2002:a17:906:7d17:: with SMTP id u23mr5437728ejo.318.1581196751427; Sat, 08 Feb 2020 13:19:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581196751; cv=none; d=google.com; s=arc-20160816; b=KKRDz9SBCyvWieHFh/qkdepE0BPlKAGJVyTe/aSmpdTjpPk63zi5mibz4qU/HyOW5D uJYLD/Kj7JqcZ5nKjIts5VveloERqCvT5OYwmVMFN3NeST+uNSGPDGhE0wTHvfsK8ZRk pwTNBjaAqXS5peyc6d2a0pPMAUR32L//V/xXllW7eIYnHdlGQXyz3TFyseuPf+Sp0NwA 7qSfdn5tiLOvwYM66TamU+JmgKRd2uqX1mXyEqum+cs3F0jeuktURfEqCatl7h5PYmQH X/Us6AEEN4ZEiGseiQB3ypjXEH8ZUMNZ7ejWo0Bs02C1gPFSe2m/E85gKu4Kf/m9wyMR 3VSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=JD+Dx4QwZ7ZPylGJNYQGiwiXxPLU/wHWV3P9sUSW4pY=; b=FqWNhiFK/fyNZ+y2pygpc6xMnh9ckVGTPeU1kHaLVsAePwxrITqDMMeXldxjGPaNFx fTLl9dzW2D5hEZ+Je52Z0u/BZnnBxFTnd+8Vw7Lpx8bWQweWodUt3TFjProEgPPOfGoe ivtaR0zcC7ABvO6K6hy3gmCcByC9iQczqpdwbGSy4D5TRFitLJisfdQpPijjoWEyjZHt 655AUWLvqkaT4FD1GyiPqXmkds6fqsp+woO4+hUC/4BGbh9l51oUFD+aXOlPdsRrryca nJmdAVSpd52yYzN/w74kavBt/rf30PIsDdXdSfz9WTsR76zc1mBWd3prR9ymiZGEFQ0E fxTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r26si1862120edp.608.2020.02.08.13.19.11; Sat, 08 Feb 2020 13:19:11 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CBEB868B082; Sat, 8 Feb 2020 23:19:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1727A68B039 for ; Sat, 8 Feb 2020 23:18:58 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id ECF8CE3B91; Sat, 8 Feb 2020 22:18:57 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id m1lhC1fVj5-U; Sat, 8 Feb 2020 22:18:56 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 86836E3ABE; Sat, 8 Feb 2020 22:18:56 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:15 +0100 Message-Id: <20200208211823.31345-4-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 04/12] avformat/http: split the fragment part from the HTTP URL before the request X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: fPTfiECHlvVX Content-Length: 1881 RFC 3986 states that the fragment identifier is separated from the rest of the URI prior to a dereference, and thus the identifying information within the fragment itself is dereferenced solely by the user agent. Signed-off-by: Marton Balint --- libavformat/http.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/http.c b/libavformat/http.c index 142511d091..5411aa0f29 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -190,6 +190,7 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src) static int http_open_cnx_internal(URLContext *h, AVDictionary **options) { const char *path, *proxy_path, *lower_proto = "tcp", *local_path; + char *hashmark; char hostname[1024], hoststr[1024], proto[10]; char auth[1024], proxyauth[1024] = ""; char path1[MAX_URL_SIZE]; @@ -215,6 +216,10 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) if (port < 0) port = 80; + hashmark = strchr(path1, '#'); + if (hashmark) + *hashmark = '\0'; + if (path1[0] == '\0') path = "/"; else From patchwork Sat Feb 8 21:18:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17721 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3D4BC44B956 for ; Sat, 8 Feb 2020 23:19:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 29BB568B083; Sat, 8 Feb 2020 23:19:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E26C768B083 for ; Sat, 8 Feb 2020 23:19:03 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 97321E3ABE; Sat, 8 Feb 2020 22:19:03 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YSrz9CH7lANi; Sat, 8 Feb 2020 22:19:01 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 95248E3925; Sat, 8 Feb 2020 22:19:00 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:16 +0100 Message-Id: <20200208211823.31345-5-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 05/12] avformat/http: make sure URL path contains a slash X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It is explicitly required by the HTTP RFC. Without this patch URLs like http://example.com?query will not work. Fixes ticket #8466. Signed-off-by: Marton Balint --- libavformat/http.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 5411aa0f29..d0df1b6d58 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -193,7 +193,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) char *hashmark; char hostname[1024], hoststr[1024], proto[10]; char auth[1024], proxyauth[1024] = ""; - char path1[MAX_URL_SIZE]; + char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE]; char buf[1024], urlbuf[MAX_URL_SIZE]; int port, use_proxy, err, location_changed = 0; HTTPContext *s = h->priv_data; @@ -220,10 +220,14 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) if (hashmark) *hashmark = '\0'; - if (path1[0] == '\0') + if (path1[0] == '\0') { path = "/"; - else + } else if (path1[0] == '?') { + snprintf(sanitized_path, sizeof(sanitized_path), "/%s", path1); + path = sanitized_path; + } else { path = path1; + } local_path = path; if (use_proxy) { /* Reassemble the request URL without auth string - we don't From patchwork Sat Feb 8 21:18:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17722 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 08D1644B956 for ; Sat, 8 Feb 2020 23:19:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E421768B07C; Sat, 8 Feb 2020 23:19:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B2E768B06E for ; Sat, 8 Feb 2020 23:19:05 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7EFD7E3B93; Sat, 8 Feb 2020 22:19:05 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DqL1hiesyvAI; Sat, 8 Feb 2020 22:19:04 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EC6BCE3B91; Sat, 8 Feb 2020 22:19:03 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:17 +0100 Message-Id: <20200208211823.31345-6-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 06/12] avformat/http: use AVBPrint to construct HTTP request X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/http.c | 79 ++++++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index d0df1b6d58..5fd36baab8 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -27,6 +27,7 @@ #include "libavutil/avassert.h" #include "libavutil/avstring.h" +#include "libavutil/bprint.h" #include "libavutil/opt.h" #include "libavutil/time.h" #include "libavutil/parseutils.h" @@ -1184,13 +1185,13 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, { HTTPContext *s = h->priv_data; int post, err; - char headers[HTTP_HEADERS_SIZE] = ""; + AVBPrint request; char *authstr = NULL, *proxyauthstr = NULL; uint64_t off = s->off; - int len = 0; const char *method; int send_expect_100 = 0; - int ret; + + av_bprint_init(&request, 0, BUFFER_SIZE); /* send http header */ post = h->flags & AVIO_FLAG_WRITE; @@ -1233,95 +1234,72 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, s->user_agent = av_strdup(s->user_agent_deprecated); } #endif + + av_bprintf(&request, "%s %s HTTP/1.1\r\n", method, path); + av_bprintf(&request, "%s", post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : ""); + /* set default headers if needed */ if (!has_header(s->headers, "\r\nUser-Agent: ")) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "User-Agent: %s\r\n", s->user_agent); + av_bprintf(&request, "User-Agent: %s\r\n", s->user_agent); if (s->referer) { /* set default headers if needed */ if (!has_header(s->headers, "\r\nReferer: ")) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Referer: %s\r\n", s->referer); + av_bprintf(&request, "Referer: %s\r\n", s->referer); } if (!has_header(s->headers, "\r\nAccept: ")) - len += av_strlcpy(headers + len, "Accept: */*\r\n", - sizeof(headers) - len); + av_bprintf(&request, "Accept: */*\r\n"); // Note: we send this on purpose even when s->off is 0 when we're probing, // since it allows us to detect more reliably if a (non-conforming) // server supports seeking by analysing the reply headers. if (!has_header(s->headers, "\r\nRange: ") && !post && (s->off > 0 || s->end_off || s->seekable == -1)) { - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Range: bytes=%"PRIu64"-", s->off); + av_bprintf(&request, "Range: bytes=%"PRIu64"-", s->off); if (s->end_off) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "%"PRId64, s->end_off - 1); - len += av_strlcpy(headers + len, "\r\n", - sizeof(headers) - len); + av_bprintf(&request, "%"PRId64, s->end_off - 1); + av_bprintf(&request, "\r\n"); } if (send_expect_100 && !has_header(s->headers, "\r\nExpect: ")) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Expect: 100-continue\r\n"); + av_bprintf(&request, "Expect: 100-continue\r\n"); if (!has_header(s->headers, "\r\nConnection: ")) { if (s->multiple_requests) - len += av_strlcpy(headers + len, "Connection: keep-alive\r\n", - sizeof(headers) - len); + av_bprintf(&request, "Connection: keep-alive\r\n"); else - len += av_strlcpy(headers + len, "Connection: close\r\n", - sizeof(headers) - len); + av_bprintf(&request, "Connection: close\r\n"); } if (!has_header(s->headers, "\r\nHost: ")) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Host: %s\r\n", hoststr); + av_bprintf(&request, "Host: %s\r\n", hoststr); if (!has_header(s->headers, "\r\nContent-Length: ") && s->post_data) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Content-Length: %d\r\n", s->post_datalen); + av_bprintf(&request, "Content-Length: %d\r\n", s->post_datalen); if (!has_header(s->headers, "\r\nContent-Type: ") && s->content_type) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Content-Type: %s\r\n", s->content_type); + av_bprintf(&request, "Content-Type: %s\r\n", s->content_type); if (!has_header(s->headers, "\r\nCookie: ") && s->cookies) { char *cookies = NULL; if (!get_cookies(s, &cookies, path, hoststr) && cookies) { - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Cookie: %s\r\n", cookies); + av_bprintf(&request, "Cookie: %s\r\n", cookies); av_free(cookies); } } if (!has_header(s->headers, "\r\nIcy-MetaData: ") && s->icy) - len += av_strlcatf(headers + len, sizeof(headers) - len, - "Icy-MetaData: %d\r\n", 1); + av_bprintf(&request, "Icy-MetaData: %d\r\n", 1); /* now add in custom headers */ if (s->headers) - av_strlcpy(headers + len, s->headers, sizeof(headers) - len); + av_bprintf(&request, "%s", s->headers); - ret = snprintf(s->buffer, sizeof(s->buffer), - "%s %s HTTP/1.1\r\n" - "%s" - "%s" - "%s" - "%s%s" - "\r\n", - method, - path, - post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "", - headers, - authstr ? authstr : "", - proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : ""); + av_bprintf(&request, "%s", authstr ? authstr : ""); + av_bprintf(&request, "%s%s\r\n", proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : ""); - av_log(h, AV_LOG_DEBUG, "request: %s\n", s->buffer); + av_log(h, AV_LOG_DEBUG, "request: %s\n", request.str); - if (strlen(headers) + 1 == sizeof(headers) || - ret >= sizeof(s->buffer)) { + if (!av_bprint_is_complete(&request)) { av_log(h, AV_LOG_ERROR, "overlong headers\n"); err = AVERROR(EINVAL); goto done; } - - if ((err = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0) + if ((err = ffurl_write(s->hd, request.str, request.len)) < 0) goto done; if (s->post_data) @@ -1362,6 +1340,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, done: av_freep(&authstr); av_freep(&proxyauthstr); + av_bprint_finalize(&request, NULL); return err; } From patchwork Sat Feb 8 21:18:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17723 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E52BC44B956 for ; Sat, 8 Feb 2020 23:19:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD3F768B08E; Sat, 8 Feb 2020 23:19:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F1C7968B03C for ; Sat, 8 Feb 2020 23:19:14 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D07EDE3B93; Sat, 8 Feb 2020 22:19:14 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id i4TOX9-Fluu3; Sat, 8 Feb 2020 22:19:13 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 08107E3925; Sat, 8 Feb 2020 22:19:13 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:18 +0100 Message-Id: <20200208211823.31345-7-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 07/12] avformat/http: escape unsafe URL path in HTTP request X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This avoids generating invalid HTTP requests if the path contains space or other special characters. Signed-off-by: Marton Balint --- libavformat/http.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libavformat/http.c b/libavformat/http.c index 5fd36baab8..6c4eeba711 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -1179,6 +1179,37 @@ static int http_read_header(URLContext *h, int *new_location) return err; } +/** + * Escape unsafe characters in path in order to pass them safely to the HTTP + * request. Insipred by the algorithm in GNU wget: + * - escape "%" characters not followed by two hex digits + * - escape all "unsafe" characters except which are also "reserved" + * - pass through everything else + */ +static void bprint_escaped_path(AVBPrint *bp, const char *path) +{ +#define NEEDS_ESCAPE(ch) \ + ((ch) <= ' ' || (ch) >= '\x7f' || \ + (ch) == '"' || (ch) == '%' || (ch) == '<' || (ch) == '>' || (ch) == '\\' || \ + (ch) == '^' || (ch) == '`' || (ch) == '{' || (ch) == '}' || (ch) == '|') + while (*path) { + char buf[1024]; + char *q = buf; + while (*path && q - buf < sizeof(buf) - 4) { + if (path[0] == '%' && av_isxdigit(path[1]) && av_isxdigit(path[2])) { + *q++ = *path++; + *q++ = *path++; + *q++ = *path++; + } else if (NEEDS_ESCAPE(*path)) { + q += snprintf(q, 4, "%%%02X", (uint8_t)*path++); + } else { + *q++ = *path++; + } + } + av_bprint_append_data(bp, buf, q - buf); + } +} + static int http_connect(URLContext *h, const char *path, const char *local_path, const char *hoststr, const char *auth, const char *proxyauth, int *new_location) @@ -1235,7 +1266,10 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, } #endif - av_bprintf(&request, "%s %s HTTP/1.1\r\n", method, path); + av_bprintf(&request, "%s ", method); + bprint_escaped_path(&request, path); + av_bprintf(&request, " HTTP/1.1\r\n"); + av_bprintf(&request, "%s", post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : ""); /* set default headers if needed */ From patchwork Sat Feb 8 21:18:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17726 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7548344B956 for ; Sat, 8 Feb 2020 23:19:25 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6341268B0A8; Sat, 8 Feb 2020 23:19:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A6E3A68B09B for ; Sat, 8 Feb 2020 23:19:18 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 904B9E3925; Sat, 8 Feb 2020 22:19:18 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Xo5eidAJcq6A; Sat, 8 Feb 2020 22:19:16 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 54C4BE3ABE; Sat, 8 Feb 2020 22:19:16 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:19 +0100 Message-Id: <20200208211823.31345-8-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 08/12] avformat/urldecode: add the ability to not decode plus sign to space X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/httpauth.c | 4 ++-- libavformat/urldecode.c | 4 ++-- libavformat/urldecode.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index 2d42ab2190..54d0322c6a 100644 --- a/libavformat/httpauth.c +++ b/libavformat/httpauth.c @@ -255,7 +255,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, if (state->auth_type == HTTP_AUTH_BASIC) { int auth_b64_len, len; - char *ptr, *decoded_auth = ff_urldecode(auth); + char *ptr, *decoded_auth = ff_urldecode(auth, 1); if (!decoded_auth) return NULL; @@ -275,7 +275,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, av_strlcat(ptr, "\r\n", len - (ptr - authstr)); av_free(decoded_auth); } else if (state->auth_type == HTTP_AUTH_DIGEST) { - char *username = ff_urldecode(auth), *password; + char *username = ff_urldecode(auth, 1), *password; if (!username) return NULL; diff --git a/libavformat/urldecode.c b/libavformat/urldecode.c index 283d912671..5261bcd0cd 100644 --- a/libavformat/urldecode.c +++ b/libavformat/urldecode.c @@ -32,7 +32,7 @@ #include "libavutil/avstring.h" #include "urldecode.h" -char *ff_urldecode(const char *url) +char *ff_urldecode(const char *url, int decode_plus_sign) { int s = 0, d = 0, url_len = 0; char c; @@ -74,7 +74,7 @@ char *ff_urldecode(const char *url) dest[d++] = c2; dest[d++] = c3; } - } else if (c == '+') { + } else if (c == '+' && decode_plus_sign) { dest[d++] = ' '; } else { dest[d++] = c; diff --git a/libavformat/urldecode.h b/libavformat/urldecode.h index cb81ebc6f7..80b11c3428 100644 --- a/libavformat/urldecode.h +++ b/libavformat/urldecode.h @@ -26,10 +26,11 @@ * in that case the original string is duplicated. * * @param url a string to be decoded. + * @param decode_plus_sign if nonzero plus sign is decoded to space * @return new string with the URL decoded or NULL if decoding failed. * Note that the returned string should be explicitly freed when not * used anymore. */ -char *ff_urldecode(const char *url); +char *ff_urldecode(const char *url, int decode_plus_sign); #endif /* AVFORMAT_URLDECODE_H */ From patchwork Sat Feb 8 21:18:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17724 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id ECA6A44B956 for ; Sat, 8 Feb 2020 23:19:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6BFD68B041; Sat, 8 Feb 2020 23:19:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1AE6F68B041 for ; Sat, 8 Feb 2020 23:19:20 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EE583E3ABE; Sat, 8 Feb 2020 22:19:19 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2t7zmUe0ecyw; Sat, 8 Feb 2020 22:19:18 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9F4D7E3B91; Sat, 8 Feb 2020 22:19:18 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:20 +0100 Message-Id: <20200208211823.31345-9-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 09/12] avformat/httpauth: do not decode plus sign to space in credentials X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/httpauth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index 54d0322c6a..4f79c78edc 100644 --- a/libavformat/httpauth.c +++ b/libavformat/httpauth.c @@ -255,7 +255,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, if (state->auth_type == HTTP_AUTH_BASIC) { int auth_b64_len, len; - char *ptr, *decoded_auth = ff_urldecode(auth, 1); + char *ptr, *decoded_auth = ff_urldecode(auth, 0); if (!decoded_auth) return NULL; @@ -275,7 +275,7 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, av_strlcat(ptr, "\r\n", len - (ptr - authstr)); av_free(decoded_auth); } else if (state->auth_type == HTTP_AUTH_DIGEST) { - char *username = ff_urldecode(auth, 1), *password; + char *username = ff_urldecode(auth, 0), *password; if (!username) return NULL; From patchwork Sat Feb 8 21:18:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17725 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A8FA344B956 for ; Sat, 8 Feb 2020 23:19:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9010D68B061; Sat, 8 Feb 2020 23:19:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 70CD568B0A5 for ; Sat, 8 Feb 2020 23:19:22 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 54002E3B91; Sat, 8 Feb 2020 22:19:22 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nAHryCXzcBo9; Sat, 8 Feb 2020 22:19:20 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C88B3E3ABE; Sat, 8 Feb 2020 22:19:20 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:21 +0100 Message-Id: <20200208211823.31345-10-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 10/12] avformat/ftp: add support for escaped credentials X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Properly fixes ticket #7816. Signed-off-by: Marton Balint --- libavformat/Makefile | 2 +- libavformat/ftp.c | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index 710cc4d088..a9972fd99a 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -592,7 +592,7 @@ OBJS-$(CONFIG_DATA_PROTOCOL) += data_uri.o OBJS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpcrypt.o rtmpdigest.o rtmpdh.o OBJS-$(CONFIG_FFRTMPHTTP_PROTOCOL) += rtmphttp.o OBJS-$(CONFIG_FILE_PROTOCOL) += file.o -OBJS-$(CONFIG_FTP_PROTOCOL) += ftp.o +OBJS-$(CONFIG_FTP_PROTOCOL) += ftp.o urldecode.o OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o OBJS-$(CONFIG_HLS_PROTOCOL) += hlsproto.o OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o urldecode.o diff --git a/libavformat/ftp.c b/libavformat/ftp.c index 97ad80de0b..860dd7d8dc 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -24,6 +24,7 @@ #include "avformat.h" #include "internal.h" #include "url.h" +#include "urldecode.h" #include "libavutil/opt.h" #include "libavutil/bprint.h" @@ -658,7 +659,7 @@ static int ftp_connect(URLContext *h, const char *url) { char proto[10], path[MAX_URL_SIZE], credentials[MAX_URL_SIZE], hostname[MAX_URL_SIZE]; const char *tok_user = NULL, *tok_pass = NULL; - char *end = NULL, *newpath = NULL; + char *newpath = NULL; int err; FTPContext *s = h->priv_data; @@ -675,21 +676,28 @@ static int ftp_connect(URLContext *h, const char *url) path, sizeof(path), url); - tok_user = av_strtok(credentials, ":", &end); - tok_pass = av_strtok(end, ":", &end); - if (!tok_user) { + if (!*credentials) { if (!s->option_user) { tok_user = "anonymous"; tok_pass = av_x_if_null(s->anonymous_password, "nopassword"); } else { tok_user = s->option_user; + tok_pass = s->option_password; } + s->user = av_strdup(tok_user); + s->password = av_strdup(tok_pass); + } else { + char *pass = strchr(credentials, ':'); + if (pass) { + *pass++ = '\0'; + tok_pass = pass; + s->password = ff_urldecode(pass, 0); + } else { + tok_pass = s->option_password; + s->password = av_strdup(tok_pass); + } + s->user = ff_urldecode(credentials, 0); } - if (!tok_pass) { - tok_pass = s->option_password; - } - s->user = av_strdup(tok_user); - s->password = av_strdup(tok_pass); s->hostname = av_strdup(hostname); if (!s->hostname || !s->user || (tok_pass && !s->password)) { return AVERROR(ENOMEM); From patchwork Sat Feb 8 21:18:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17727 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 62E1C44B956 for ; Sat, 8 Feb 2020 23:19:28 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5120568B06E; Sat, 8 Feb 2020 23:19:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A23768B083 for ; Sat, 8 Feb 2020 23:19:26 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id F0219E3925; Sat, 8 Feb 2020 22:19:25 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id doCa_0Y_1YEG; Sat, 8 Feb 2020 22:19:24 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3110DE3B91; Sat, 8 Feb 2020 22:19:23 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:22 +0100 Message-Id: <20200208211823.31345-11-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 11/12] avformat/ftp: do not break protocol on username or password with newlines X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavformat/ftp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavformat/ftp.c b/libavformat/ftp.c index 860dd7d8dc..ab7368256c 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "libavutil/avstring.h" #include "libavutil/internal.h" #include "libavutil/parseutils.h" @@ -246,10 +248,14 @@ static int ftp_auth(FTPContext *s) static const int user_codes[] = {331, 230, 0}; static const int pass_codes[] = {230, 0}; + if (strpbrk(s->user, "\r\n")) + return AVERROR(EINVAL); snprintf(buf, sizeof(buf), "USER %s\r\n", s->user); err = ftp_send_command(s, buf, user_codes, NULL); if (err == 331) { if (s->password) { + if (strpbrk(s->password, "\r\n")) + return AVERROR(EINVAL); snprintf(buf, sizeof(buf), "PASS %s\r\n", s->password); err = ftp_send_command(s, buf, pass_codes, NULL); } else From patchwork Sat Feb 8 21:18:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 17728 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 304A044B956 for ; Sat, 8 Feb 2020 23:19:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1F1F568B05C; Sat, 8 Feb 2020 23:19:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8663768B0B0 for ; Sat, 8 Feb 2020 23:19:28 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 5EB7AE3925; Sat, 8 Feb 2020 22:19:28 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IyxdMxoufhYr; Sat, 8 Feb 2020 22:19:26 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 41F72E3B93; Sat, 8 Feb 2020 22:19:25 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 8 Feb 2020 22:18:23 +0100 Message-Id: <20200208211823.31345-12-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200208211823.31345-1-cus@passwd.hu> References: <20200208211823.31345-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 12/12] avformat/ftp: slightly rework file retrieval with seeking X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" - do not require a known file size for seek to work - read the files till the actual end, do not limit data at the queried file size - fix a bug which causes reading 0 byte files for non-existing files - properly check the return status of the FTP server at the end of the file retrieval Signed-off-by: Marton Balint --- libavformat/ftp.c | 54 +++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/libavformat/ftp.c b/libavformat/ftp.c index ab7368256c..e3d194da58 100644 --- a/libavformat/ftp.c +++ b/libavformat/ftp.c @@ -39,7 +39,8 @@ typedef enum { DOWNLOADING, UPLOADING, LISTING_DIR, - DISCONNECTED + DISCONNECTED, + ENDOFFILE, } FTPState; typedef enum { @@ -231,7 +232,6 @@ static int ftp_send_command(FTPContext *s, const char *command, static void ftp_close_data_connection(FTPContext *s) { ffurl_closep(&s->conn_data); - s->position = 0; s->state = DISCONNECTED; } @@ -740,8 +740,7 @@ static int ftp_open(URLContext *h, const char *url, int flags) if (ftp_restart(s, 0) < 0) { h->is_streamed = 1; } else { - if (ftp_file_size(s) < 0 && flags & AVIO_FLAG_READ) - h->is_streamed = 1; + ftp_file_size(s); if (s->write_seekable != 1 && flags & AVIO_FLAG_WRITE) h->is_streamed = 1; } @@ -758,7 +757,7 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence) { FTPContext *s = h->priv_data; int err; - int64_t new_pos, fake_pos; + int64_t new_pos; ff_dlog(h, "ftp protocol seek %"PRId64" %d\n", pos, whence); @@ -788,11 +787,10 @@ static int64_t ftp_seek(URLContext *h, int64_t pos, int whence) return AVERROR(EINVAL); } - fake_pos = s->filesize != -1 ? FFMIN(new_pos, s->filesize) : new_pos; - if (fake_pos != s->position) { + if (new_pos != s->position) { if ((err = ftp_abort(h)) < 0) return err; - s->position = fake_pos; + s->position = new_pos; } return new_pos; } @@ -804,16 +802,13 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size) ff_dlog(h, "ftp protocol read %d bytes\n", size); retry: + if (s->state == ENDOFFILE) + return AVERROR_EOF; if (s->state == DISCONNECTED) { - /* optimization */ - if (s->position >= s->filesize) - return AVERROR_EOF; if ((err = ftp_connect_data_connection(h)) < 0) return err; } if (s->state == READY) { - if (s->position >= s->filesize) - return AVERROR_EOF; if ((err = ftp_retrieve(s)) < 0) return err; } @@ -821,27 +816,28 @@ static int ftp_read(URLContext *h, unsigned char *buf, int size) read = ffurl_read(s->conn_data, buf, size); if (read >= 0) { s->position += read; - if (s->position >= s->filesize) { - /* server will terminate, but keep current position to avoid madness */ - /* save position to restart from it */ - int64_t pos = s->position; - if (ftp_abort(h) < 0) { - s->position = pos; - return AVERROR(EIO); - } - s->position = pos; - } + s->filesize = FFMAX(s->filesize, s->position); + } + if (read == AVERROR_EOF) { + static const int retr_codes[] = {226, 250, 425, 426, 451, 0}; + char *response = NULL; + err = ftp_status(s, &response, retr_codes); + if (err == 226) { + ftp_close_data_connection(s); + av_freep(&response); + s->state = ENDOFFILE; + return AVERROR_EOF; + } + /* 250 is not allowed, any other status means some kind of error */ + av_log(h, AV_LOG_ERROR, "FTP transfer failed: %s\n", response ? response : (err < 0 ? av_err2str(err) : "?")); + av_freep(&response); + read = AVERROR(EIO); } - if (read <= 0 && s->position < s->filesize && !h->is_streamed) { + if (read <= 0 && !h->is_streamed) { /* Server closed connection. Probably due to inactivity */ - int64_t pos = s->position; av_log(h, AV_LOG_INFO, "Reconnect to FTP server.\n"); if ((err = ftp_abort(h)) < 0) return err; - if ((err = ftp_seek(h, pos, SEEK_SET)) < 0) { - av_log(h, AV_LOG_ERROR, "Position cannot be restored.\n"); - return err; - } if (!retry_done) { retry_done = 1; goto retry;