X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fvariables.c;h=904ae746aebe116d8f4ab6a2e276f0b750971815;hb=77f7cdd4cb65332ed8343e3ed973b92f77fbaa03;hp=9ba21f7aa66064860d10347de97b2517aa083528;hpb=da1291a1a42561d1bc15543dbe9cc00ebcb5a312;p=vlc diff --git a/src/misc/variables.c b/src/misc/variables.c index 9ba21f7aa6..904ae746ae 100644 --- a/src/misc/variables.c +++ b/src/misc/variables.c @@ -352,8 +352,7 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) for( i = 0 ; i < p_var->choices.i_count ; i++ ) { p_var->pf_free( &p_var->choices.p_values[i] ); - if( p_var->choices_text.p_values[i].psz_string ) - free( p_var->choices_text.p_values[i].psz_string ); + free( p_var->choices_text.p_values[i].psz_string ); } free( p_var->choices.p_values ); free( p_var->choices_text.p_values ); @@ -366,7 +365,7 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) } free( p_var->psz_name ); - if( p_var->psz_text ) free( p_var->psz_text ); + free( p_var->psz_text ); memmove( p_priv->p_vars + i_var, p_priv->p_vars + i_var + 1, @@ -520,8 +519,7 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, } p_var->pf_free( &p_var->choices.p_values[i] ); - if( p_var->choices_text.p_values[i].psz_string ) - free( p_var->choices_text.p_values[i].psz_string ); + free( p_var->choices_text.p_values[i].psz_string ); REMOVE_ELEM( p_var->choices.p_values, p_var->choices.i_count, i ); REMOVE_ELEM( p_var->choices_text.p_values, p_var->choices_text.i_count, i ); @@ -537,10 +535,8 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, p_var->pf_free( &p_var->choices.p_values[i] ); } for( i = 0 ; i < p_var->choices_text.i_count ; i++ ) - { - if( p_var->choices_text.p_values[i].psz_string ) - free( p_var->choices_text.p_values[i].psz_string ); - } + free( p_var->choices_text.p_values[i].psz_string ); + if( p_var->choices.i_count ) free( p_var->choices.p_values ); if( p_var->choices_text.i_count ) free( p_var->choices_text.p_values ); @@ -620,8 +616,7 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, if( p_val2 && p_val2->p_list ) { for( i = 0; i < p_val2->p_list->i_count; i++ ) - if( p_val2->p_list->p_values[i].psz_string ) - free( p_val2->p_list->p_values[i].psz_string ); + free( p_val2->p_list->p_values[i].psz_string ); if( p_val2->p_list->i_count ) { free( p_val2->p_list->p_values ); @@ -631,7 +626,7 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, } break; case VLC_VAR_SETTEXT: - if( p_var->psz_text ) free( p_var->psz_text ); + free( p_var->psz_text ); if( p_val && p_val->psz_string ) p_var->psz_text = strdup( p_val->psz_string ); break; @@ -1041,31 +1036,34 @@ int __var_TriggerCallback( vlc_object_t *p_this, const char *psz_name ) * option name and bar is the value of the option. * \param p_obj the object in which the variable must be created * \param psz_option the option to parse + * \param trusted whether the option is set by a trusted input or not * \return nothing */ -void __var_OptionParse( vlc_object_t *p_obj, const char *psz_option ) +void var_OptionParse( vlc_object_t *p_obj, const char *psz_option, + bool trusted ) { - char *psz_name, *psz_value = strchr( psz_option, '=' ); - int i_name_len, i_type; + char *psz_name, *psz_value; + int i_type; vlc_bool_t b_isno = VLC_FALSE; vlc_value_t val; - val.psz_string = NULL; - if( psz_value ) i_name_len = psz_value - psz_option; - else i_name_len = strlen( psz_option ); + val.psz_string = NULL; /* It's too much of a hassle to remove the ':' when we parse * the cmd line :) */ if( psz_option[0] == ':' ) - { psz_option++; - i_name_len--; - } - if( i_name_len == 0 ) return; + if( !psz_option[0] ) + return; - psz_name = strndup( psz_option, i_name_len ); - if( psz_value ) psz_value++; + psz_name = strdup( psz_option ); + if( psz_name == NULL ) + return; + + psz_value = strchr( psz_name, '=' ); + if( psz_value != NULL ) + *psz_value++ = '\0'; /* FIXME: :programs should be handled generically */ if( !strcmp( psz_name, "programs" ) ) @@ -1088,40 +1086,21 @@ void __var_OptionParse( vlc_object_t *p_obj, const char *psz_option ) b_isno = VLC_TRUE; i_type = config_GetType( p_obj, psz_name ); - - if( !i_type ) goto cleanup; /* Option doesn't exist */ } - else if( !i_type ) goto cleanup; /* Option doesn't exist */ + if( !i_type ) goto cleanup; /* Option doesn't exist */ if( ( i_type != VLC_VAR_BOOL ) && ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */ /* check if option is unsafe */ + if( !trusted ) { module_config_t *p_config = config_FindConfig( p_obj, psz_name ); if( !p_config->b_safe ) { - int policy = config_GetInt( p_obj, "security-policy" ); - switch( policy ) - { - case 0: /* block */ - msg_Err( p_obj, "option %s is unsafe and is blocked by security policy", psz_name ); - return; - case 1: /* allow */ - break; - case 2: /* prompt */ - { - char description[256]; - snprintf(description, sizeof(description), _("playlist item is making use of the following unsafe option '%s', which may be harmful if used in a malicious way, authorize it ?"), psz_name); - if( DIALOG_OK_YES != intf_UserYesNo( p_obj, _("WARNING: Unsafe Playlist"), description, _("Yes"), _("No"), NULL) ) - { - msg_Err( p_obj, "option %s is unsafe and is blocked by security policy", psz_name ); - return; - } - } - default: - ; - } + msg_Err( p_obj, "unsafe option \"%s\" has been ignored for " + "security reasons", psz_name ); + return; } } @@ -1177,20 +1156,18 @@ void __var_OptionParse( vlc_object_t *p_obj, const char *psz_option ) INSERT_ELEM( p_list->pi_types, p_list->i_count, p_list->i_count, VLC_VAR_INTEGER ); } - if( psz_orig ) free( psz_orig ); + free( psz_orig ); break; } default: goto cleanup; - break; } var_Set( p_obj, psz_name, val ); - cleanup: - if( psz_name ) free( psz_name ); - return; +cleanup: + free( psz_name ); } @@ -1535,7 +1512,7 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name, INSERT_ELEM( p_list->pi_types, p_list->i_count, p_list->i_count, VLC_VAR_INTEGER ); } - if( psz_orig ) free( psz_orig ); + free( psz_orig ); break; } default: