From patchwork Mon Apr 27 10:51:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 19293 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 2A4D544B8B5 for ; Mon, 27 Apr 2020 13:52:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 092CA68C1EF; Mon, 27 Apr 2020 13:52:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 643B868BB9E for ; Mon, 27 Apr 2020 13:52:09 +0300 (EEST) X-QQ-mid: bizesmtp25t1587984712traq1e1w Received: from localhost (unknown [221.216.234.164]) by esmtp10.qq.com (ESMTP) with id ; Mon, 27 Apr 2020 18:51:49 +0800 (CST) X-QQ-SSF: 01100000002000K0ZUF0000A0000000 X-QQ-FEAT: da60yr+1N74KkIc8a0SRYJ3O0/5gn7CQtwoUG+Mol5R+YqxN6bGwhjqX4krUW OSo/pzD8Iq91IbHSzhFOCc2sMtHyNgOaEVYSJYFygp2zBHEiSroCKTvOt405n0/Ys327w7A JxpolNgFwns0vVyC7F8QUr/65Vzbv8bL2BTjBrCMjS+Ft7N17SUNjJOHSN92c1Ay2ZDHBEI r46LYibOCly+pBbSozJFr6fA40ygtDXcQizNQdbgrWfD8adK5DlQSN3AnU17iib/ksTEwlS 10A5TDUY3pjU3RYVLao7eTCadaKWYr0sLIb35Gy6H8Z/JariXLDnJ8DTYVpXldQ7biYyD/C DDCgXMbcuANtuMhBrO/uIPp0w7blA== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 27 Apr 2020 18:51:47 +0800 Message-Id: <20200427105147.98947-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v2] avformat/url: check url root node when rel include double dot 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: Steven Liu , Steven Liu , =?utf-8?q?Martin_Storsj=C3=B6?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" fix ticket: 8625 and add testcase into url for double dot corner case Suggested-by: Martin Storsjö Signed-off-by: Steven Liu --- libavformat/tests/url.c | 3 +++ libavformat/url.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c index 5e484fd428..02d0d59aa8 100644 --- a/libavformat/tests/url.c +++ b/libavformat/tests/url.c @@ -56,6 +56,7 @@ int main(void) test("/foo/bar", "baz"); test("/foo/bar", "../baz"); test("/foo/bar", "/baz"); + test("/foo/bar", "../../../baz"); test("http://server/foo/", "baz"); test("http://server/foo/bar", "baz"); test("http://server/foo/", "../baz"); @@ -65,6 +66,8 @@ 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"); + test("http://server/foo/bar", "../../../../../other/url"); + test("http://server/foo/bar", "/../../../../../other/url"); printf("\nTesting av_url_split:\n"); test2("/foo/bar"); diff --git a/libavformat/url.c b/libavformat/url.c index 596fb49cfc..0aa50ab9a7 100644 --- a/libavformat/url.c +++ b/libavformat/url.c @@ -81,6 +81,7 @@ void ff_make_absolute_url(char *buf, int size, const char *base, const char *rel) { char *sep, *path_query; + char *root, *p; /* Absolute path, relative to the current server */ if (base && strstr(base, "://") && rel[0] == '/') { if (base != buf) @@ -120,16 +121,32 @@ void ff_make_absolute_url(char *buf, int size, const char *base, return; } + root = p = buf; + /* Get the path root of the url which start by "://" */ + if (p && strstr(p, "://")) { + sep = strstr(p, "://"); + if (sep) { + sep += 3; + root = strchr(sep, '/'); + } + } + /* Remove the file name from the base url */ sep = strrchr(buf, '/'); + if (sep <= root) + sep = root; + if (sep) sep[1] = '\0'; else buf[0] = '\0'; while (av_strstart(rel, "../", NULL) && sep) { /* Remove the path delimiter at the end */ - sep[0] = '\0'; - sep = strrchr(buf, '/'); + if (sep > root) { + sep[0] = '\0'; + sep = strrchr(buf, '/'); + } + /* If the next directory name to pop off is "..", break here */ if (!strcmp(sep ? &sep[1] : buf, "..")) { /* Readd the slash we just removed */