]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/sgimb.c
Do not assert memory allocations
[vlc] / modules / demux / playlist / sgimb.c
index f6552fec816d3bd6444d03190f5b47c2edba35c8..d0a32004857905aa14eb0c40e9d6b78dc2f387e4 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_demux.h>
 #include "playlist.h"
 
@@ -211,6 +211,7 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
     if( !strncasecmp( psz_bol, "rtsp://", sizeof("rtsp://") - 1 ) )
     {
         /* We found the link, it was inside a sgiQTFileBegin */
+        free( p_sys->psz_uri );
         p_sys->psz_uri = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "Stream=\"", sizeof("Stream=\"") - 1 ) )
@@ -218,7 +219,10 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
         psz_bol += sizeof("Stream=\"") - 1;
         if ( !psz_bol )
             return 0;
-        strrchr( psz_bol, '"' )[0] = '\0';
+        char* psz_tmp = strrchr( psz_bol, '"' );
+        if( !psz_tmp )
+            return 0;
+        psz_tmp[0] = '\0';
         /* We cheat around xdma. for some reason xdma links work different then rtsp */
         if( !strncasecmp( psz_bol, "xdma://", sizeof("xdma://") - 1 ) )
         {
@@ -227,31 +231,37 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
             psz_bol[2] = 's';
             psz_bol[3] = 'p';
         }
+        free( p_sys->psz_uri );
         p_sys->psz_uri = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiNameServerHost=", sizeof("sgiNameServerHost=") - 1 ) )
     {
         psz_bol += sizeof("sgiNameServerHost=") - 1;
+        free( p_sys->psz_server );
         p_sys->psz_server = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiMovieName=", sizeof("sgiMovieName=") - 1 ) )
     {
         psz_bol += sizeof("sgiMovieName=") - 1;
+        free( p_sys->psz_location );
         p_sys->psz_location = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiUserAccount=", sizeof("sgiUserAccount=") - 1 ) )
     {
         psz_bol += sizeof("sgiUserAccount=") - 1;
+        free( p_sys->psz_user );
         p_sys->psz_user = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiUserPassword=", sizeof("sgiUserPassword=") - 1 ) )
     {
         psz_bol += sizeof("sgiUserPassword=") - 1;
+        free( p_sys->psz_password );
         p_sys->psz_password = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiShowingName=", sizeof("sgiShowingName=") - 1 ) )
     {
         psz_bol += sizeof("sgiShowingName=") - 1;
+        free( p_sys->psz_name );
         p_sys->psz_name = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiFormatName=", sizeof("sgiFormatName=") - 1 ) )
@@ -263,6 +273,7 @@ static int ParseLine ( demux_t *p_demux, char *psz_line )
     else if( !strncasecmp( psz_bol, "sgiMulticastAddress=", sizeof("sgiMulticastAddress=") - 1 ) )
     {
         psz_bol += sizeof("sgiMulticastAddress=") - 1;
+        free( p_sys->psz_mcast_ip );
         p_sys->psz_mcast_ip = strdup( psz_bol );
     }
     else if( !strncasecmp( psz_bol, "sgiMulticastPort=", sizeof("sgiMulticastPort=") - 1 ) )
@@ -313,7 +324,7 @@ static int Demux ( demux_t *p_demux )
     input_item_t    *p_child = NULL;
     char            *psz_line;
 
-    INIT_PLAYLIST_STUFF;
+    input_item_t *p_current_input = GetCurrentItem(p_demux);
 
     while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
     {
@@ -325,25 +336,24 @@ static int Demux ( demux_t *p_demux )
     {
         /* Definetly schedules multicast session */
         /* We don't care if it's live or not */
-        char *temp;
-
-        asprintf( &temp, "udp://@" "%s:%i", p_sys->psz_mcast_ip, p_sys->i_mcast_port );
         free( p_sys->psz_uri );
-        p_sys->psz_uri = strdup( temp );
-        free( temp );
+        if( asprintf( &p_sys->psz_uri, "udp://@" "%s:%i", p_sys->psz_mcast_ip, p_sys->i_mcast_port ) == -1 )
+        {
+            p_sys->psz_uri = NULL;
+            return -1;
+        }
     }
 
     if( p_sys->psz_uri == NULL )
     {
         if( p_sys->psz_server && p_sys->psz_location )
         {
-            char *temp;
-
-            asprintf( &temp, "rtsp://" "%s:%i%s",
-                     p_sys->psz_server, p_sys->i_port > 0 ? p_sys->i_port : 554, p_sys->psz_location );
-
-            p_sys->psz_uri = strdup( temp );
-            free( temp );
+            if( asprintf( &p_sys->psz_uri, "rtsp://" "%s:%i%s",
+                     p_sys->psz_server, p_sys->i_port > 0 ? p_sys->i_port : 554, p_sys->psz_location ) == -1 )
+            {
+                p_sys->psz_uri = NULL;
+                return -1;
+            }
         }
     }
 
@@ -351,25 +361,24 @@ static int Demux ( demux_t *p_demux )
     {
         /* It's definetly a simulcasted scheduled stream */
         /* We don't care if it's live or not */
-        char *temp;
-
         if( p_sys->psz_uri == NULL )
         {
             msg_Err( p_demux, "no URI was found" );
             return -1;
         }
 
-        asprintf( &temp, "%s%%3FMeDiAbAsEshowingId=%d%%26MeDiAbAsEconcert%%3FMeDiAbAsE",
-                p_sys->psz_uri, p_sys->i_sid );
-
         free( p_sys->psz_uri );
-        p_sys->psz_uri = strdup( temp );
-        free( temp );
+        if( asprintf( &p_sys->psz_uri, "%s%%3FMeDiAbAsEshowingId=%d%%26MeDiAbAsEconcert%%3FMeDiAbAsE",
+                p_sys->psz_uri, p_sys->i_sid ) == -1 )
+        {
+            p_sys->psz_uri = NULL;
+            return -1;
+        }
     }
 
-    p_child = input_ItemNewWithType( (vlc_object_t *)p_playlist, p_sys->psz_uri,
+    p_child = input_item_NewWithType( VLC_OBJECT(p_demux), p_sys->psz_uri,
                       p_sys->psz_name ? p_sys->psz_name : p_sys->psz_uri,
-                      0, NULL, p_sys->i_duration, ITEM_TYPE_NET );
+                      0, NULL, 0, p_sys->i_duration, ITEM_TYPE_NET );
  
     if( !p_child )
     {
@@ -377,33 +386,25 @@ static int Demux ( demux_t *p_demux )
         return -1;
     }
 
-    input_ItemCopyOptions( p_current_input, p_child );
+    input_item_CopyOptions( p_current_input, p_child );
     if( p_sys->i_packet_size && p_sys->psz_mcast_ip )
     {
         char *psz_option;
         p_sys->i_packet_size += 1000;
-        asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
+        if( asprintf( &psz_option, "mtu=%i", p_sys->i_packet_size ) != -1 )
+        {
+            input_item_AddOption( p_child, psz_option, VLC_INPUT_OPTION_TRUSTED );
+            free( psz_option );
+        }
     }
     if( !p_sys->psz_mcast_ip )
-    {
-        char *psz_option;
-        asprintf( &psz_option, "rtsp-caching=5000" );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
-    }
+        input_item_AddOption( p_child, "rtsp-caching=5000", VLC_INPUT_OPTION_TRUSTED );
     if( !p_sys->psz_mcast_ip && p_sys->b_rtsp_kasenna )
-    {
-        char *psz_option;
-        asprintf( &psz_option, "rtsp-kasenna" );
-        input_ItemAddOption( p_child, psz_option );
-        free( psz_option );
-    }
+        input_item_AddOption( p_child, "rtsp-kasenna", VLC_INPUT_OPTION_TRUSTED );
 
-    input_ItemAddSubItem( p_current_input, p_child );
+    input_item_AddSubItem( p_current_input, p_child );
     vlc_gc_decref( p_child );
-    HANDLE_PLAY_AND_RELEASE
+    vlc_gc_decref(p_current_input);
     return 0; /* Needed for correct operation of go back */
 }