[vlc-devel] [PATCH] variables: fix null-deref when the inherited variable is not in config

Thomas Guillem thomas at gllm.fr
Fri Mar 2 13:37:01 CET 2018


Regression from 0f69e188d4c7c130db30707c9fd3b70c0bc10fa2
---
 src/misc/variables.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index 0bf6bbad0e..f5ee7f420c 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -1180,21 +1180,29 @@ int var_Inherit( vlc_object_t *p_this, const char *psz_name, int i_type,
             return VLC_SUCCESS;
     }
 
+    const bool has_config = config_GetType( psz_name ) != 0;
+
     /* else take value from config */
     switch( i_type & VLC_VAR_CLASS )
     {
         case VLC_VAR_STRING:
-            p_val->psz_string = config_GetPsz( psz_name );
-            if( !p_val->psz_string ) p_val->psz_string = strdup("");
+            if( has_config )
+                p_val->psz_string = config_GetPsz( psz_name );
+            if( !p_val->psz_string )
+            {
+                p_val->psz_string = strdup("");
+                if( !p_val->psz_string )
+                    return VLC_ENOMEM;
+            }
             break;
         case VLC_VAR_FLOAT:
-            p_val->f_float = config_GetFloat( psz_name );
+            p_val->f_float = has_config ? config_GetFloat( psz_name ) : -1;
             break;
         case VLC_VAR_INTEGER:
-            p_val->i_int = config_GetInt( psz_name );
+            p_val->i_int = has_config ? config_GetInt( psz_name ) : -1;
             break;
         case VLC_VAR_BOOL:
-            p_val->b_bool = config_GetInt( psz_name ) > 0;
+            p_val->b_bool = has_config ? config_GetInt( psz_name ) > 0 : false;
             break;
         default:
             vlc_assert_unreachable();
-- 
2.11.0



More information about the vlc-devel mailing list