diff mbox series

[FFmpeg-devel,3/3] avformat/dashdec: avoid calling strlen multiple times

Message ID 1642909918-26903-3-git-send-email-lance.lmwang@gmail.com
State Accepted
Commit 1530b3f56630b93d0395860bbf3ce03510099990
Headers show
Series [FFmpeg-devel,1/3] avformat/rtpdec: Fix negative missed packets in warning message | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Lance Wang Jan. 23, 2022, 3:51 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/dashdec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Steven Liu Jan. 24, 2022, 3:48 a.m. UTC | #1
<lance.lmwang@gmail.com> 于2022年1月23日周日 11:52写道:
>
> From: Limin Wang <lance.lmwang@gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavformat/dashdec.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 0d21989..211d77f 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -403,6 +403,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
>      DASHContext *c = s->priv_data;
>      AVDictionary *tmp = NULL;
>      const char *proto_name = NULL;
> +    int proto_name_len;
>      int ret;
>
>      if (av_strstart(url, "crypto", NULL)) {
> @@ -416,6 +417,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
>      if (!proto_name)
>          return AVERROR_INVALIDDATA;
>
> +    proto_name_len = strlen(proto_name);
>      // only http(s) & file are allowed
>      if (av_strstart(proto_name, "file", NULL)) {
>          if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
> @@ -430,9 +432,9 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
>      } else
>          return AVERROR_INVALIDDATA;
>
> -    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
> +    if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] == ':')
>          ;
> -    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
> +    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, proto_name_len) && url[7 + proto_name_len] == ':')
>          ;
>      else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
>          return AVERROR_INVALIDDATA;
> --
> 1.8.3.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

lgtm


Thanks
Lance Wang Jan. 30, 2022, 5:40 a.m. UTC | #2
On Mon, Jan 24, 2022 at 11:48:22AM +0800, Steven Liu wrote:
> <lance.lmwang@gmail.com> 于2022年1月23日周日 11:52写道:
> >
> > From: Limin Wang <lance.lmwang@gmail.com>
> >
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavformat/dashdec.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> > index 0d21989..211d77f 100644
> > --- a/libavformat/dashdec.c
> > +++ b/libavformat/dashdec.c
> > @@ -403,6 +403,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
> >      DASHContext *c = s->priv_data;
> >      AVDictionary *tmp = NULL;
> >      const char *proto_name = NULL;
> > +    int proto_name_len;
> >      int ret;
> >
> >      if (av_strstart(url, "crypto", NULL)) {
> > @@ -416,6 +417,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
> >      if (!proto_name)
> >          return AVERROR_INVALIDDATA;
> >
> > +    proto_name_len = strlen(proto_name);
> >      // only http(s) & file are allowed
> >      if (av_strstart(proto_name, "file", NULL)) {
> >          if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
> > @@ -430,9 +432,9 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
> >      } else
> >          return AVERROR_INVALIDDATA;
> >
> > -    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
> > +    if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] == ':')
> >          ;
> > -    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
> > +    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, proto_name_len) && url[7 + proto_name_len] == ':')
> >          ;
> >      else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
> >          return AVERROR_INVALIDDATA;
> > --
> > 1.8.3.1
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> lgtm

thanks, will push the patch set tomorrow if no other comments.

> 
> 
> Thanks
diff mbox series

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 0d21989..211d77f 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -403,6 +403,7 @@  static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
     DASHContext *c = s->priv_data;
     AVDictionary *tmp = NULL;
     const char *proto_name = NULL;
+    int proto_name_len;
     int ret;
 
     if (av_strstart(url, "crypto", NULL)) {
@@ -416,6 +417,7 @@  static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
     if (!proto_name)
         return AVERROR_INVALIDDATA;
 
+    proto_name_len = strlen(proto_name);
     // only http(s) & file are allowed
     if (av_strstart(proto_name, "file", NULL)) {
         if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {
@@ -430,9 +432,9 @@  static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,
     } else
         return AVERROR_INVALIDDATA;
 
-    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
+    if (!strncmp(proto_name, url, proto_name_len) && url[proto_name_len] == ':')
         ;
-    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')
+    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, proto_name_len) && url[7 + proto_name_len] == ':')
         ;
     else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))
         return AVERROR_INVALIDDATA;