[FFmpeg-devel,v1] avformat/hlsenc: fix the av_dirname path isn't include / in the end of string

Submitted by lance.lmwang@gmail.com on Oct. 8, 2019, 2:31 p.m.

Details

Message ID 20191008143114.29043-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Oct. 8, 2019, 2:31 p.m.
From: Limin Wang <lance.lmwang@gmail.com>

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

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cd43201..ad27d7d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -544,7 +544,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
     while (segment) {
         av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
                segment->filename);
-        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
+        path_size =  (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 2;
         path = av_malloc(path_size);
         if (!path) {
             ret = AVERROR(ENOMEM);
@@ -554,8 +554,7 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         if (hls->use_localtime_mkdir)
             av_strlcpy(path, segment->filename, path_size);
         else { // segment->filename contains basename only
-            av_strlcpy(path, dirname, path_size);
-            av_strlcat(path, segment->filename, path_size);
+            snprintf(path, path_size, "%s/%s", dirname, segment->filename);
         }
 
         proto = avio_find_protocol_name(s->url);
@@ -575,15 +574,14 @@  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
         if ((segment->sub_filename[0] != '\0')) {
             char *vtt_dirname_r = av_strdup(vs->vtt_avf->url);
             vtt_dirname = (char*)av_dirname(vtt_dirname_r);
-            sub_path_size = strlen(segment->sub_filename) + 1 + strlen(vtt_dirname);
+            sub_path_size = strlen(segment->sub_filename) + 2 + strlen(vtt_dirname);
             sub_path = av_malloc(sub_path_size);
             if (!sub_path) {
                 ret = AVERROR(ENOMEM);
                 goto fail;
             }
 
-            av_strlcpy(sub_path, vtt_dirname, sub_path_size);
-            av_strlcat(sub_path, segment->sub_filename, sub_path_size);
+            snprintf(sub_path, sub_path_size, "%s/%s", vtt_dirname, segment->sub_filename);
 
             if (hls->method || (proto && !av_strcasecmp(proto, "http"))) {
                 av_dict_set(&options, "method", "DELETE", 0);