]> git.sesse.net Git - vlc/commitdiff
hds: fix memory leak and buffer probing
authorTristan Matthews <le.businessman@gmail.com>
Fri, 1 Aug 2014 05:24:19 +0000 (01:24 -0400)
committerTristan Matthews <le.businessman@gmail.com>
Fri, 1 Aug 2014 14:17:02 +0000 (10:17 -0400)
Only 200 bytes are peeked but FromCharset was being called with 512.
The char * returned by FromCharset was not being freed, and
strstr was being called on a buffer that was not NULL terminated
(in the non utf-8 case).

modules/stream_filter/hds/hds.c

index edf615913057f82afe3cf0bbf1c828a94e4275c7..af3181def1d136aed93f21ce747d253c43c76185 100644 (file)
@@ -186,23 +186,24 @@ static bool isHDS( stream_t *s )
     if( i_size < 200 )
         return false;
 
-    const char *str;
+    char *str;
 
     if( !memcmp( peek, "\xFF\xFE", 2 ) )
     {
-        str = FromCharset( "UTF-16LE", peek, 512 );
+        str = FromCharset( "UTF-16LE", peek, i_size );
     }
     else if( !memcmp( peek, "\xFE\xFF", 2 ) )
     {
-        str = FromCharset( "UTF-16BE", peek, 512 );
+        str = FromCharset( "UTF-16BE", peek, i_size );
     }
     else
-        str = peek;
+        str = strndup( peek, i_size );
 
     if( str == NULL )
         return false;
 
     bool ret = strstr( str, "<manifest" ) != NULL;
+    free( str );
     return ret;
 }