[vlc-commits] access: dvb: scan: fix scan parameter alloc/free/const violation

Francois Cartegnie git at videolan.org
Sun Apr 10 13:56:10 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Apr  6 15:02:07 2016 +0200| [d510f69bceb1cff36fcd1e8e3899ce07479d176a] | committer: Francois Cartegnie

access: dvb: scan: fix scan parameter alloc/free/const violation

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d510f69bceb1cff36fcd1e8e3899ce07479d176a
---

 modules/access/dvb/access.c    |    6 +++++-
 modules/access/dvb/dvb.h       |    2 +-
 modules/access/dvb/linux_dvb.c |    5 +----
 modules/access/dvb/scan.c      |   27 +++++++++++++++++++++++----
 modules/access/dvb/scan.h      |    3 +++
 5 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/modules/access/dvb/access.c b/modules/access/dvb/access.c
index 348f7d7..cadac3d 100644
--- a/modules/access/dvb/access.c
+++ b/modules/access/dvb/access.c
@@ -157,17 +157,21 @@ static int Open( vlc_object_t *p_this )
         scan_parameter_t parameter;
         scan_t *p_scan;
 
+        scan_parameter_Init( &parameter );
+
         msg_Dbg( p_access, "setting filter on PAT/NIT/SDT (DVB only)" );
         FilterSet( p_access, 0x00, OTHER_TYPE );    // PAT
         FilterSet( p_access, 0x10, OTHER_TYPE );    // NIT
         FilterSet( p_access, 0x11, OTHER_TYPE );    // SDT
 
-        if( FrontendGetScanParameter( p_access, &parameter ) ||
+        if( FrontendFillScanParameter( p_access, &parameter ) ||
             (p_scan = scan_New( VLC_OBJECT(p_access), &parameter )) == NULL )
         {
+            scan_parameter_Clean( &parameter );
             Close( VLC_OBJECT(p_access) );
             return VLC_EGENERIC;
         }
+        scan_parameter_Clean( &parameter );
         p_sys->scan = p_scan;
         p_sys->i_read_once = DVB_READ_ONCE_SCAN;
     }
diff --git a/modules/access/dvb/dvb.h b/modules/access/dvb/dvb.h
index 15f5dc7..9c5eadf 100644
--- a/modules/access/dvb/dvb.h
+++ b/modules/access/dvb/dvb.h
@@ -91,7 +91,7 @@ void FrontendClose( access_t * );
 
 int  FrontendGetStatistic( access_t *, frontend_statistic_t * );
 void FrontendGetStatus( access_t *, frontend_status_t * );
-int  FrontendGetScanParameter( access_t *, struct scan_parameter_t * );
+int  FrontendFillScanParameter( access_t *, struct scan_parameter_t * );
 
 int DMXSetFilter( access_t *, int i_pid, int * pi_fd, int i_type );
 int DMXUnsetFilter( access_t *, int i_fd );
diff --git a/modules/access/dvb/linux_dvb.c b/modules/access/dvb/linux_dvb.c
index 337f0a3..e9361db 100644
--- a/modules/access/dvb/linux_dvb.c
+++ b/modules/access/dvb/linux_dvb.c
@@ -383,7 +383,6 @@ static int ScanParametersDvbS( access_t *p_access, scan_parameter_t *p_scan )
 {
     const frontend_t *p_frontend = p_access->p_sys->p_frontend;
 
-    memset( p_scan, 0, sizeof(*p_scan) );
     p_scan->type = SCAN_DVB_S;
 
     p_scan->frequency.i_min = p_frontend->info.frequency_min;
@@ -398,7 +397,6 @@ static int ScanParametersDvbC( access_t *p_access, scan_parameter_t *p_scan )
 {
     const frontend_t *p_frontend = p_access->p_sys->p_frontend;
 
-    memset( p_scan, 0, sizeof(*p_scan) );
     p_scan->type = SCAN_DVB_C;
     p_scan->b_exhaustive = false;
 
@@ -437,7 +435,6 @@ static int ScanParametersDvbT( access_t *p_access, scan_parameter_t *p_scan )
 {
     const frontend_t *p_frontend = p_access->p_sys->p_frontend;
 
-    memset( p_scan, 0, sizeof(*p_scan) );
     p_scan->type = SCAN_DVB_T;
     p_scan->b_exhaustive = false;
 
@@ -456,7 +453,7 @@ static int ScanParametersDvbT( access_t *p_access, scan_parameter_t *p_scan )
     return VLC_SUCCESS;
 }
 
-int  FrontendGetScanParameter( access_t *p_access, scan_parameter_t *p_scan )
+int  FrontendFillScanParameter( access_t *p_access, scan_parameter_t *p_scan )
 {
     access_sys_t *p_sys = p_access->p_sys;
     const frontend_t *p_frontend = p_sys->p_frontend;
diff --git a/modules/access/dvb/scan.c b/modules/access/dvb/scan.c
index 20a6634..5a188dc 100644
--- a/modules/access/dvb/scan.c
+++ b/modules/access/dvb/scan.c
@@ -184,6 +184,25 @@ static int scan_service_type( int service_type )
     }
 }
 
+void scan_parameter_Init( scan_parameter_t *p_dst )
+{
+    memset( p_dst, 0, sizeof(*p_dst) );
+}
+
+void scan_parameter_Clean( scan_parameter_t *p_dst )
+{
+    if( p_dst->sat_info.psz_name )
+        free( p_dst->sat_info.psz_name );
+}
+
+static void scan_parameter_Copy( const scan_parameter_t *p_src, scan_parameter_t *p_dst )
+{
+    scan_parameter_Clean( p_dst );
+    *p_dst = *p_src;
+    if( p_src->sat_info.psz_name )
+        p_dst->sat_info.psz_name = strdup( p_src->sat_info.psz_name );
+}
+
 /* */
 scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter )
 {
@@ -226,7 +245,8 @@ scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter )
     p_scan->i_index = 0;
     p_scan->p_dialog_id = NULL;
     TAB_INIT( p_scan->i_service, p_scan->pp_service );
-    p_scan->parameter = *p_parameter;
+    scan_parameter_Init( &p_scan->parameter );
+    scan_parameter_Copy( p_parameter, &p_scan->parameter );
     p_scan->i_time_start = mdate();
 
     return p_scan;
@@ -239,6 +259,8 @@ void scan_Destroy( scan_t *p_scan )
     if( p_scan->p_dialog_id != NULL )
         vlc_dialog_release( p_scan->p_obj, p_scan->p_dialog_id );
 
+    scan_parameter_Clean( &p_scan->parameter );
+
     for( int i = 0; i < p_scan->i_service; i++ )
         scan_service_Delete( p_scan->pp_service[i] );
     TAB_CLEAN( p_scan->i_service, p_scan->pp_service );
@@ -266,7 +288,6 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
                        p_scan->parameter.sat_info.psz_name ) == -1 )
         {
             free( data_dir );
-            free( p_scan->parameter.sat_info.psz_name );
             return VLC_EGENERIC;
         }
         free( data_dir );
@@ -277,7 +298,6 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
         if( !f )
         {
             msg_Err( p_scan->p_obj, "failed to open satellite file (%s)", psz_path );
-            free( p_scan->parameter.sat_info.psz_name );
             free( psz_path );
             return VLC_EGENERIC;
         }
@@ -329,7 +349,6 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
 
         p_scan->p_transponders = p_transponders;
         fclose( f );
-        free( p_scan->parameter.sat_info.psz_name );
     }
 
     if( p_scan->i_index < p_scan->i_transponders )
diff --git a/modules/access/dvb/scan.h b/modules/access/dvb/scan.h
index d0a8005..4f3c717 100644
--- a/modules/access/dvb/scan.h
+++ b/modules/access/dvb/scan.h
@@ -82,6 +82,9 @@ typedef struct
 
 typedef struct scan_t scan_t;
 
+void scan_parameter_Init( scan_parameter_t * );
+void scan_parameter_Clean( scan_parameter_t * );
+
 scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter );
 void scan_Destroy( scan_t *p_scan );
 



More information about the vlc-commits mailing list