diff mbox series

[FFmpeg-devel] libavformat/url: check url root node when rel include double dot

Message ID 20200427102405.96226-1-lq@chinaffmpeg.org
State Superseded
Headers show
Series [FFmpeg-devel] libavformat/url: check url root node when rel include double dot | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Liu Steven April 27, 2020, 10:24 a.m. UTC
fix ticket: 8625

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/url.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Comments

Martin Storsjö April 27, 2020, 10:30 a.m. UTC | #1
On Mon, 27 Apr 2020, Steven Liu wrote:

> fix ticket: 8625
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
> libavformat/url.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/url.c b/libavformat/url.c
> index 596fb49cfc..e5003f795a 100644
> --- a/libavformat/url.c
> +++ b/libavformat/url.c
> @@ -81,6 +81,8 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
>                           const char *rel)
> {
>     char *sep, *path_query;
> +    char *root = NULL;
> +    char *p = NULL;
>     /* Absolute path, relative to the current server */
>     if (base && strstr(base, "://") && rel[0] == '/') {
>         if (base != buf)

There's a good set of tests for this function in libavformat/tests/url.c - 
please add a new testcase there for the thing you are implementing (and 
ideally, also any other closely related corner case).

// Martin
Liu Steven April 27, 2020, 10:38 a.m. UTC | #2
> 2020年4月27日 下午6:30,Martin Storsjö <martin@martin.st> 写道:
> 
> On Mon, 27 Apr 2020, Steven Liu wrote:
> 
>> fix ticket: 8625
>> 
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>> libavformat/url.c | 22 ++++++++++++++++++++--
>> 1 file changed, 20 insertions(+), 2 deletions(-)
>> 
>> diff --git a/libavformat/url.c b/libavformat/url.c
>> index 596fb49cfc..e5003f795a 100644
>> --- a/libavformat/url.c
>> +++ b/libavformat/url.c
>> @@ -81,6 +81,8 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
>>                          const char *rel)
>> {
>>    char *sep, *path_query;
>> +    char *root = NULL;
>> +    char *p = NULL;
>>    /* Absolute path, relative to the current server */
>>    if (base && strstr(base, "://") && rel[0] == '/') {
>>        if (base != buf)
> 
> There's a good set of tests for this function in libavformat/tests/url.c - please add a new testcase there for the thing you are implementing (and ideally, also any other closely related corner case).
Ok. Let me try to add them into the test case. Thanks Martin.
> 
> // Martin

Thanks

Steven Liu
diff mbox series

Patch

diff --git a/libavformat/url.c b/libavformat/url.c
index 596fb49cfc..e5003f795a 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -81,6 +81,8 @@  void ff_make_absolute_url(char *buf, int size, const char *base,
                           const char *rel)
 {
     char *sep, *path_query;
+    char *root = NULL;
+    char *p = NULL;
     /* Absolute path, relative to the current server */
     if (base && strstr(base, "://") && rel[0] == '/') {
         if (base != buf)
@@ -120,16 +122,32 @@  void ff_make_absolute_url(char *buf, int size, const char *base,
         return;
     }
 
+    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 */