]> git.sesse.net Git - vlc/blobdiff - modules/access/cdda.c
Fix potential double free (cid #1047496 and #1047497)
[vlc] / modules / access / cdda.c
index 76480dc5915316412b024937a798522d745069a5..e46185905547070f20cd3da508479db2bedb384f 100644 (file)
@@ -1,30 +1,30 @@
 /*****************************************************************************
  * cdda.c : CD digital audio input module for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2003-2006, 2008-2009 the VideoLAN team
+ * Copyright (C) 2000, 2003-2006, 2008-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@netcourrier.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /**
  * Todo:
- *   - Improve CDDB support (non-blocking, cache, ...)
+ *   - Improve CDDB support (non-blocking, ...)
  *   - Fix tracknumber in MRL
  */
 
@@ -75,10 +75,11 @@ vlc_module_begin ()
         change_volatile ()
 
 #ifdef HAVE_LIBCDDB
-    add_string( "cddb-server", "freedb.freedb.org", N_( "CDDB Server" ),
+    add_string( "cddb-server", "freedb.videolan.org", N_( "CDDB Server" ),
             N_( "Address of the CDDB server to use." ), true )
-    add_integer( "cddb-port", 8880, N_( "CDDB port" ),
+    add_integer( "cddb-port", 80, N_( "CDDB port" ),
             N_( "CDDB Server port to use." ), true )
+        change_integer_range( 1, 65535 )
 #endif
 
     add_shortcut( "cdda", "cddasimple" )
@@ -141,7 +142,7 @@ static int Open( vlc_object_t *p_this )
     }
     else psz_name = ToLocaleDup( p_access->psz_filepath );
 
-#if defined( WIN32 ) || defined( __OS2__ )
+#if defined( _WIN32 ) || defined( __OS2__ )
     if( psz_name[0] && psz_name[1] == ':' &&
         psz_name[2] == '\\' && psz_name[3] == '\0' ) psz_name[2] = '\0';
 #endif
@@ -159,11 +160,11 @@ static int Open( vlc_object_t *p_this )
     STANDARD_BLOCK_ACCESS_INIT
     p_sys->vcddev = vcddev;
 
-   /* Do we play a single track ? */
-   p_sys->i_track = var_InheritInteger( p_access, "cdda-track" ) - 1;
+    /* Do we play a single track ? */
+    p_sys->i_track = var_InheritInteger( p_access, "cdda-track" ) - 1;
 
-   if( p_sys->i_track < 0 )
-   {
+    if( p_sys->i_track < 0 )
+    {
         /* We only do separate items if the whole disc is requested */
         input_thread_t *p_input = access_GetParentInput( p_access );
 
@@ -261,7 +262,7 @@ static block_t *Block( access_t *p_access )
     if( !p_sys->b_header )
     {
         /* Return only the header */
-        p_block = block_New( p_access, sizeof( WAVEHEADER ) );
+        p_block = block_Alloc( sizeof( WAVEHEADER ) );
         memcpy( p_block->p_buffer, &p_sys->waveheader, sizeof(WAVEHEADER) );
         p_sys->b_header = true;
         return p_block;
@@ -278,7 +279,7 @@ static block_t *Block( access_t *p_access )
         i_blocks = p_sys->i_last_sector - p_sys->i_sector;
 
     /* Do the actual reading */
-    if( !( p_block = block_New( p_access, i_blocks * CDDA_DATA_SIZE ) ) )
+    if( !( p_block = block_Alloc( i_blocks * CDDA_DATA_SIZE ) ) )
     {
         msg_Err( p_access, "cannot get a new block of size: %i",
                  i_blocks * CDDA_DATA_SIZE );
@@ -602,6 +603,9 @@ static cddb_disc_t *GetCDDBInfo( access_t *p_access, int i_titles, int *p_sector
     }
 
     /* */
+
+    cddb_http_enable( p_cddb );
+
     char *psz_tmp = var_InheritString( p_access, "cddb-server" );
     if( psz_tmp )
     {
@@ -613,17 +617,21 @@ static cddb_disc_t *GetCDDBInfo( access_t *p_access, int i_titles, int *p_sector
 
     cddb_set_email_address( p_cddb, "vlc@videolan.org" );
 
-    /// \todo
-    cddb_cache_disable( p_cddb );
+    cddb_set_http_path_query( p_cddb, "/~cddb/cddb.cgi" );
+    cddb_set_http_path_submit( p_cddb, "/~cddb/submit.cgi" );
 
-//    cddb_cache_set_dir( p_cddb,
-//                     var_InheritString( p_access,
-//                                    MODULE_STRING "-cddb-cachedir") );
 
-    cddb_set_timeout( p_cddb, 10 );
+    char *psz_cachedir;
+    char *psz_temp = config_GetUserDir( VLC_CACHE_DIR );
 
-    /// \todo
-    cddb_http_disable( p_cddb );
+    if( asprintf( &psz_cachedir, "%s" DIR_SEP "cddb", psz_temp ) > 0 ) {
+        cddb_cache_enable( p_cddb );
+        cddb_cache_set_dir( p_cddb, psz_cachedir );
+        free( psz_cachedir );
+    }
+    free( psz_temp );
+
+    cddb_set_timeout( p_cddb, 10 );
 
     /* */
     cddb_disc_t *p_disc = cddb_disc_new();