[vlc-devel] [PATCH 07/48] Always append a null character when reading HLS playlist

Hugo Beauzée-Luyssen beauze.h at gmail.com
Mon Jan 9 16:16:16 CET 2012


From: Luc Saillard <luc.saillard at sfr.com>

The httplive module doesn't always append a null character after reading the
playlist. Many str* function is used on the playlist buffer (strstr, printf,
...). We must ensure that the buffer is null terminated, else we will read
random data.

We also have two functions readM3u8() and read_M3u8() that does the same
job. Rewrite it into read_M3U8_from_url() and read_M3U8_from_stream().

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

Conflicts:

	modules/stream_filter/httplive.c
---
 modules/stream_filter/httplive.c |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 1282618..35d5da2 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -43,6 +43,7 @@
 #include <vlc_url.h>
 #include <vlc_memory.h>
 #include <vlc_gcrypt.h>
+#include <vlc_memory.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -151,8 +152,8 @@ static int  Read   (stream_t *, void *p_read, unsigned int i_read);
 static int  Peek   (stream_t *, const uint8_t **pp_peek, unsigned int i_peek);
 static int  Control(stream_t *, int i_query, va_list);
 
-static ssize_t read_M3U8(stream_t *s, const char *psz_url, uint8_t **buffer);
-static ssize_t ReadM3U8(stream_t *s, uint8_t **buffer);
+static ssize_t read_M3U8_from_stream(stream_t *s, uint8_t **buffer);
+static ssize_t read_M3U8_from_url(stream_t *s, const char *url, uint8_t **buffer);
 static char *ReadLine(uint8_t *buffer, uint8_t **pos, size_t len);
 
 static int hls_Download(stream_t *s, segment_t *segment);
@@ -997,7 +998,7 @@ static int parse_M3U8(stream_t *s, vlc_array_t *streams, uint8_t *buffer, const
 
                     /* Download playlist file from server */
                     uint8_t *buf = NULL;
-                    ssize_t len = read_M3U8(s, hls->url, &buf);
+                    ssize_t len = read_M3U8_from_url(s, hls->uri, &buf);
                     if (len < 0)
                         err = VLC_EGENERIC;
                     else
@@ -1272,7 +1273,7 @@ static int get_HTTPLiveMetaPlaylist(stream_t *s, vlc_array_t **streams)
 
     /* Download new playlist file from server */
     uint8_t *buffer = NULL;
-    ssize_t len = read_M3U8(s, p_sys->m3u8_playlist, &buffer);
+    ssize_t len = read_M3U8_from_url(s, p_sys->m3u8_playlist, &buffer);
     if (len < 0)
         return VLC_EGENERIC;
 
@@ -1819,17 +1820,11 @@ static ssize_t read_M3U8_from_stream(stream_t *s, uint8_t **buffer)
     return total_bytes;
 }
 
-static ssize_t read_M3U8_from_url(stream_t *s, vlc_url_t *url, uint8_t **buffer)
+static ssize_t read_M3U8_from_url(stream_t *s, const char *url, uint8_t **buffer)
 {
     assert(*buffer == NULL);
 
-    /* Construct URL */
-    char *psz_url = ConstructUrl(url);
-    if (psz_url == NULL)
-           return VLC_ENOMEM;
-
-    stream_t *p_m3u8 = stream_UrlNew(s, psz_url);
-    free(psz_url);
+    stream_t *p_m3u8 = stream_UrlNew(s, url);
     if (p_m3u8 == NULL)
         return VLC_EGENERIC;
 
-- 
1.7.8.3




More information about the vlc-devel mailing list