[vlc-devel] [PATCH 01/12] config: chain: Don't use VLA

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Dec 8 15:19:05 CET 2020


---
 src/config/chain.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/config/chain.c b/src/config/chain.c
index 514a571ab7..6f26b7b4e0 100644
--- a/src/config/chain.c
+++ b/src/config/chain.c
@@ -271,7 +271,6 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
                         const char *const *ppsz_options, const config_chain_t *cfg )
 {
     if( psz_prefix == NULL ) psz_prefix = "";
-    size_t plen = 1 + strlen( psz_prefix );
 
     /* First, var_Create all variables */
     for( size_t i = 0; ppsz_options[i] != NULL; i++ )
@@ -280,11 +279,15 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         if (optname[0] == '*')
             optname++;
 
-        char name[plen + strlen( optname )];
-        snprintf( name, sizeof (name), "%s%s", psz_prefix, optname );
+        char* name;
+        if( asprintf(&name, "%s%s", psz_prefix, optname) < 0 )
+            return;
         if( var_Create( p_this, name,
                         config_GetType( name ) | VLC_VAR_DOINHERIT ) )
+        {
+            free(name);
             return /* VLC_xxx */;
+        }
 
         module_config_t* p_conf = config_FindConfig( name );
         if( p_conf )
@@ -303,6 +306,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
                     break;
             }
         }
+        free(name);
     }
 
     /* Now parse options and set value */
@@ -349,10 +353,11 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         }
 
         /* create name */
-        char name[plen + strlen( ppsz_options[i] )];
-        const char *psz_name = name;
-        snprintf( name, sizeof (name), "%s%s", psz_prefix,
-                  b_once ? (ppsz_options[i] + 1) : ppsz_options[i] );
+        char *name;
+        if (asprintf(&name, "%s%s", psz_prefix,
+                     b_once ? (ppsz_options[i] + 1) : ppsz_options[i]) < 0)
+            continue;
+        const char* psz_name = name;
 
         /* Check if the option is deprecated */
         p_conf = config_FindConfig( name );
@@ -368,6 +373,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
                 /* TODO: this should return an error and end option parsing
                  * ... but doing this would change the VLC API and all the
                  * modules so i'll do it later */
+                free(name);
                 continue;
             }
         }
@@ -379,17 +385,20 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         {
             msg_Warn( p_this, "unknown option %s (value=%s)",
                       cfg->psz_name, cfg->psz_value );
+            free(name);
             continue;
         }
 
         if( i_type != VLC_VAR_BOOL && cfg->psz_value == NULL )
         {
             msg_Warn( p_this, "missing value for option %s", cfg->psz_name );
+            free(name);
             continue;
         }
         if( i_type != VLC_VAR_STRING && b_once )
         {
             msg_Warn( p_this, "*option_name need to be a string option" );
+            free(name);
             continue;
         }
 
@@ -422,6 +431,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
             {
                 free( val2.psz_string );
                 msg_Dbg( p_this, "ignoring option %s (not first occurrence)", psz_name );
+                free(name);
                 continue;
             }
             free( val2.psz_string );
@@ -429,6 +439,7 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
         var_Set( p_this, psz_name, val );
         msg_Dbg( p_this, "set config option: %s to %s", psz_name,
                  cfg->psz_value ? cfg->psz_value : "(null)" );
+        free(name);
     }
 }
 
-- 
2.29.2



More information about the vlc-devel mailing list