diff mbox series

[FFmpeg-devel,v2] libavformat/hls: use local var url for log to avoid crash

Message ID 20201019020757.12101-1-javashu2012@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v2] libavformat/hls: use local var url for log to avoid crash
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate warning Make fate failed

Commit Message

徐慧书 Oct. 19, 2020, 2:07 a.m. UTC
From: bevis <javashu2012@gmail.com>

During operation, the user exits and interrupts, causing pls->segment to be released, resulting in a null pointer crash

Signed-off-by: bevis <javashu2012@gmail.com>
---
 libavformat/hls.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Steven Liu Oct. 22, 2020, 9:14 a.m. UTC | #1
> 2020年10月19日 上午10:07,javashu2012@gmail.com 写道:
> 
> From: bevis <javashu2012@gmail.com>
> 
> During operation, the user exits and interrupts, causing pls->segment to be released, resulting in a null pointer crash
> 
> Signed-off-by: bevis <javashu2012@gmail.com>
> ---
> libavformat/hls.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 72e28ab94f..0a522a4595 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -1979,17 +1979,18 @@ static int hls_read_header(AVFormatContext *s)
>         pls->ctx->interrupt_callback = s->interrupt_callback;
>         url = av_strdup(pls->segments[0]->url);
>         ret = av_probe_input_buffer(&pls->pb, &in_fmt, url, NULL, 0, 0);
> -        av_free(url);
>         if (ret < 0) {
>             /* Free the ctx - it isn't initialized properly at this point,
>              * so avformat_close_input shouldn't be called. If
>              * avformat_open_input fails below, it frees and zeros the
>              * context, so it doesn't need any special treatment like this. */
> -            av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", pls->segments[0]->url);
> +            av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", url);
>             avformat_free_context(pls->ctx);
>             pls->ctx = NULL;
> +            av_free(url);
>             goto fail;
>         }
> +        av_free(url);
>         pls->ctx->pb       = &pls->pb;
>         pls->ctx->io_open  = nested_io_open;
>         pls->ctx->flags   |= s->flags & ~AVFMT_FLAG_CUSTOM_IO;
> -- 
> 2.21.1 (Apple Git-122.3)
> 
> _______________________________________________
> 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".


Applied


Thanks

Steven Liu
diff mbox series

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 72e28ab94f..0a522a4595 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1979,17 +1979,18 @@  static int hls_read_header(AVFormatContext *s)
         pls->ctx->interrupt_callback = s->interrupt_callback;
         url = av_strdup(pls->segments[0]->url);
         ret = av_probe_input_buffer(&pls->pb, &in_fmt, url, NULL, 0, 0);
-        av_free(url);
         if (ret < 0) {
             /* Free the ctx - it isn't initialized properly at this point,
              * so avformat_close_input shouldn't be called. If
              * avformat_open_input fails below, it frees and zeros the
              * context, so it doesn't need any special treatment like this. */
-            av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", pls->segments[0]->url);
+            av_log(s, AV_LOG_ERROR, "Error when loading first segment '%s'\n", url);
             avformat_free_context(pls->ctx);
             pls->ctx = NULL;
+            av_free(url);
             goto fail;
         }
+        av_free(url);
         pls->ctx->pb       = &pls->pb;
         pls->ctx->io_open  = nested_io_open;
         pls->ctx->flags   |= s->flags & ~AVFMT_FLAG_CUSTOM_IO;