From 4708cdd12292995b44ed8433190a1b3857ac35e8 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Wed, 1 Jul 2015 10:56:09 +0300 Subject: [PATCH] Add a mechanism for handling checkers disabled for security. --- plugin/syntastic.vim | 2 +- plugin/syntastic/checker.vim | 23 +++++++++++++++++++++++ plugin/syntastic/registry.vim | 18 +++++++++++++++++- syntax_checkers/elixir/elixir.vim | 9 ++------- syntax_checkers/perl/perl.vim | 9 ++------- syntax_checkers/r/svtools.vim | 8 ++------ 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 177805cf..cee769d5 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -19,7 +19,7 @@ if has('reltime') lockvar! g:_SYNTASTIC_START endif -let g:_SYNTASTIC_VERSION = '3.6.0-114' +let g:_SYNTASTIC_VERSION = '3.6.0-115' lockvar g:_SYNTASTIC_VERSION " Sanity checks {{{1 diff --git a/plugin/syntastic/checker.vim b/plugin/syntastic/checker.vim index 89772cc2..b0d10c07 100644 --- a/plugin/syntastic/checker.vim +++ b/plugin/syntastic/checker.vim @@ -25,6 +25,10 @@ function! g:SyntasticChecker.New(args) abort " {{{2 let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_' endif + if has_key(a:args, 'enable') + let newObj._enable = a:args['enable'] + endif + let newObj._locListFunc = function(prefix . 'GetLocList') if exists('*' . prefix . 'IsAvailable') @@ -78,6 +82,21 @@ endfunction " }}}2 function! g:SyntasticChecker.getLocListRaw() abort " {{{2 let name = self._filetype . '/' . self._name + + if has_key(self, '_enable') + let status = syntastic#util#var(self._enable, -1) + if status < 0 + call syntastic#log#error('checker ' . name . ': checks disabled for security reasons; ' . + \ 'set g:syntastic_' . self._enable . ' to 1 to override') + endif + if status <= 0 + call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, 'getLocList: checker ' . name . ' enabled but not forced') + return [] + else + call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, 'getLocList: checker ' . name . ' forced') + endif + endif + try let list = self._locListFunc() if self._exec !=# '' @@ -152,6 +171,10 @@ function! g:SyntasticChecker.isAvailable() abort " {{{2 return self._available endfunction " }}}2 +function! g:SyntasticChecker.isDisabled() abort " {{{2 + return has_key(self, '_enable') && syntastic#util#var(self._enable, -1) <= 0 +endfunction " }}}2 + function! g:SyntasticChecker.wantSort() abort " {{{2 return syntastic#util#var(self._filetype . '_' . self._name . '_sort', 0) endfunction " }}}2 diff --git a/plugin/syntastic/registry.vim b/plugin/syntastic/registry.vim index 2a09a73e..310a290a 100644 --- a/plugin/syntastic/registry.vim +++ b/plugin/syntastic/registry.vim @@ -181,12 +181,18 @@ function! g:SyntasticRegistry.getCheckers(ftalias, hints_list) abort " {{{2 \ self._filterCheckersByName(checkers_map, names) : [checkers_map[keys(checkers_map)[0]]] endfunction " }}}2 -" Same as getCheckers(), but keep only the checkers available. This runs the +" Same as getCheckers(), but keep only the available checkers. This runs the " corresponding IsAvailable() functions for all checkers. function! g:SyntasticRegistry.getCheckersAvailable(ftalias, hints_list) abort " {{{2 return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isAvailable()') endfunction " }}}2 +" Same as getCheckers(), but keep only the checkers tyhat are available and +" disabled. This runs the corresponding IsAvailable() functions for all checkers. +function! g:SyntasticRegistry.getCheckersDisabled(ftalias, hints_list) abort " {{{2 + return filter(self.getCheckers(a:ftalias, a:hints_list), 'v:val.isDisabled() && v:val.isAvailable()') +endfunction " }}}2 + function! g:SyntasticRegistry.getKnownFiletypes() abort " {{{2 let types = keys(s:_DEFAULT_CHECKERS) @@ -214,15 +220,18 @@ function! g:SyntasticRegistry.echoInfoFor(ftalias_list) abort " {{{2 if len(ft_list) != 1 let available = [] let active = [] + let disabled = [] for ft in ft_list call extend(available, map( self.getNamesOfAvailableCheckers(ft), 'ft . "/" . v:val' )) call extend(active, map( self.getCheckersAvailable(ft, []), 'ft . "/" . v:val.getName()' )) + call extend(disabled, map( self.getCheckersDisabled(ft, []), 'ft . "/" . v:val.getName()' )) endfor else let ft = ft_list[0] let available = self.getNamesOfAvailableCheckers(ft) let active = map(self.getCheckersAvailable(ft, []), 'v:val.getName()') + let disabled = map(self.getCheckersDisabled(ft, []), 'v:val.getName()') endif let cnt = len(available) @@ -235,6 +244,13 @@ function! g:SyntasticRegistry.echoInfoFor(ftalias_list) abort " {{{2 let cklist = cnt ? join(active) : '-' echomsg 'Currently enabled checker' . plural . ': ' . cklist + let cnt = len(disabled) + let plural = cnt != 1 ? 's' : '' + if len(disabled) + let cklist = join(sort(disabled)) + echomsg 'Checker' . plural . ' disabled for security reasons: ' . cklist + endif + " Eclim feels entitled to mess with syntastic's variables {{{3 if exists(':EclimValidate') && get(g:, 'EclimFileTypeValidate', 1) let disabled = filter(copy(ft_list), 's:_disabled_by_eclim(v:val)') diff --git a/syntax_checkers/elixir/elixir.vim b/syntax_checkers/elixir/elixir.vim index 1aa1de37..f2ffe67e 100644 --- a/syntax_checkers/elixir/elixir.vim +++ b/syntax_checkers/elixir/elixir.vim @@ -27,12 +27,6 @@ function! SyntaxCheckers_elixir_elixir_IsAvailable() dict endfunction function! SyntaxCheckers_elixir_elixir_GetLocList() dict - if !syntastic#util#var('enable_elixir_checker', 0) - call syntastic#log#error('checker elixir/elixir: checks disabled for security reasons; ' . - \ 'set g:syntastic_enable_elixir_checker to 1 to override') - return [] - endif - let make_options = {} let compile_command = 'elixir' let mix_file = syntastic#util#findFileInParent('mix.exs', expand('%:p:h', 1)) @@ -53,7 +47,8 @@ endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'elixir', - \ 'name': 'elixir'}) + \ 'name': 'elixir', + \ 'enable': 'enable_elixir_checker'}) let &cpo = s:save_cpo unlet s:save_cpo diff --git a/syntax_checkers/perl/perl.vim b/syntax_checkers/perl/perl.vim index 0462d2d2..93f82042 100644 --- a/syntax_checkers/perl/perl.vim +++ b/syntax_checkers/perl/perl.vim @@ -51,12 +51,6 @@ function! SyntaxCheckers_perl_perl_IsAvailable() dict endfunction function! SyntaxCheckers_perl_perl_GetLocList() dict - if !syntastic#util#var('enable_perl_checker', 0) - call syntastic#log#error('checker perl/perl: checks disabled for security reasons; ' . - \ 'set g:syntastic_enable_perl_checker to 1 to override') - return [] - endif - if type(g:syntastic_perl_lib_path) == type('') call syntastic#log#oneTimeWarn('variable g:syntastic_perl_lib_path should be a list') let includes = split(g:syntastic_perl_lib_path, ',') @@ -91,7 +85,8 @@ endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'perl', - \ 'name': 'perl'}) + \ 'name': 'perl', + \ 'enable': 'enable_perl_checker'}) let &cpo = s:save_cpo unlet s:save_cpo diff --git a/syntax_checkers/r/svtools.vim b/syntax_checkers/r/svtools.vim index bd96206a..d2a6a748 100644 --- a/syntax_checkers/r/svtools.vim +++ b/syntax_checkers/r/svtools.vim @@ -46,11 +46,6 @@ function! SyntaxCheckers_r_svtools_IsAvailable() dict endfunction function! SyntaxCheckers_r_svtools_GetLocList() dict - if !syntastic#util#var('enable_r_svtools_checker', 0) - call syntastic#log#error('checker r/svtools: checks disabled for security reasons; set g:syntastic_enable_r_svtools_checker to 1 to override') - return [] - endif - let setwd = syntastic#util#isRunningWindows() ? 'setwd("' . escape(getcwd(), '"\') . '"); ' : '' let makeprg = self.getExecEscaped() . ' --slave --restore --no-save' . \ ' -e ' . syntastic#util#shescape(setwd . 'library(svTools); ' . @@ -70,7 +65,8 @@ endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'r', \ 'name': 'svtools', - \ 'exec': 'R' }) + \ 'exec': 'R', + \ 'enable': 'enable_r_svtools_checker'}) let &cpo = s:save_cpo unlet s:save_cpo