Hi,

When opening a Perl file with option 'filetype plugin on'
and with command line option -Z (restricted mode), vim
displays an error message.

I can reproduce it for example with:

  $ vim -u NONE -Z -c 'filetype plugin on | e foo.pl'
  "foo.pl" [New File]
  Error detected while processing /usr/local/share/vim/vim71/ftplugin/perl.vim:
  line   46:
  E145: Shell commands not allowed in rvim
  Press ENTER or type command to continue


Error happens because -Z prevents running shell commands and
standard script vim71/ftplugin/perl.vim contains a system() call:

 42 " Set this once, globally.
 43 if !exists("perlpath")
 44     if executable("perl")
 45         if &shellxquote != '"'
!46             let perlpath = system('perl -e "print join(q/,/,@INC)"')
 47         else
 48             let perlpath = system("perl -e 'print join(q/,/,@INC)'")
 49         endif
 50         let perlpath = substitute(perlpath,',.$',',,','')
 51     else
 52         " If we can't call perl to get its path, just default to using the
 53         " current directory and the directory of the current file.
 54         let perlpath = ".,,"
 55     endif
 56 endif

Perhaps the standard script perl.vim should not call system(...)
when running in restricted mode.

>From a user point of view, one would expect to be able to use the
-Z command line option even with Perl script.  Note that I observed
this error only with Perl file types.  I don't think there should
be anything special about Perl scripts.

Furthermore, valgrind memory checker complains with using uninitialized
values when using the same command:

% valgrind vim -u NONE -Z -c 'filetype plugin on | e foo.pl' 2> vg.log

==11318== Use of uninitialised value of size 4
==11318==    at 0x47917FB: (within /lib/tls/i686/cmov/libc-2.6.1.so)
==11318==    by 0x4793799: vfprintf (in /lib/tls/i686/cmov/libc-2.6.1.so)
==11318==    by 0x47B033B: vsprintf (in /lib/tls/i686/cmov/libc-2.6.1.so)
==11318==    by 0x479B9BD: sprintf (in /lib/tls/i686/cmov/libc-2.6.1.so)
==11318==    by 0x808A03D: get_tv_string_buf_chk (eval.c:17753)
==11318==    by 0x8089FF5: get_tv_string_chk (eval.c:17742)
==11318==    by 0x8073A3F: ex_let_one (eval.c:2250)
==11318==    by 0x8072D7A: ex_let_vars (eval.c:1790)
==11318==    by 0x8072D2B: ex_let (eval.c:1755)
==11318==    by 0x80A511A: do_one_cmd (ex_docmd.c:2623)
==11318==    by 0x80A2966: do_cmdline (ex_docmd.c:1099)
==11318==    by 0x80A0BEB: do_source (ex_cmds2.c:3054)
==11318==    by 0x80A00C9: source_callback (ex_cmds2.c:2501)
==11318==    by 0x80A02DB: do_in_runtimepath (ex_cmds2.c:2595)
==11318==    by 0x80A00F3: source_runtime (ex_cmds2.c:2515)
==11318==    by 0x80A00A6: ex_runtime (ex_cmds2.c:2490)
==11318==    by 0x80A511A: do_one_cmd (ex_docmd.c:2623)
==11318==    by 0x80A2966: do_cmdline (ex_docmd.c:1099)
==11318==    by 0x808B6DA: ex_execute (eval.c:18592)
==11318==    by 0x80A511A: do_one_cmd (ex_docmd.c:2623)
==11318==    by 0x80A2966: do_cmdline (ex_docmd.c:1099)
==11318==    by 0x808F04A: call_user_func (eval.c:20289)
==11318==    by 0x807B7BE: call_func (eval.c:7599)
==11318==    by 0x807B3E9: get_func_tv (eval.c:7446)
==11318==    by 0x80755CE: ex_call (eval.c:3213)

(then follow several other errors with uninitialized values...)

eval.c:

  17745     static char_u *
  17746 get_tv_string_buf_chk(varp, buf)
  17747     typval_T    *varp;
  17748     char_u      *buf;
  17749 {
  17750     switch (varp->v_type)
  17751     {
  17752         case VAR_NUMBER:
!!17753             sprintf((char *)buf, "%ld", (long)varp->vval.v_number);
  17754             return buf;
  17755         case VAR_FUNC:

So even though varp->v_type is equal to VAR_NUMBER,
'varp->vval.v_number' is not initialized (and used at line 17753)

I suppose that it's a consequence of the fact that system(...)
could not be run in -Z mode.  In any case, vim should not call
sprintf(...) with an uninitialized value even if system(...)
call is not allowed to run.

Looking at eval.c, I see that almost wherever varp->v_type
is initialized to VAR_NUMBER, varp->vval.v_number is
also initialized.  Except in one location (line eval.c:7551).
If I initialize v_number there, then valgrind no longer complains
about using uninitialized values.   I attach a one line patch
but I'm not sure whether that's correct. Perhaps something
else should be done when system(...) can't can't run?

I'm using vim-7.1 (Patches 1-164) on Linux built with:
- configure --with-features=huge
- -g -O0  (no optimizations)

-- Dominique

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Index: eval.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/eval.c,v
retrieving revision 1.237
diff -c -r1.237 eval.c
*** eval.c	8 Nov 2007 19:49:02 -0000	1.237
--- eval.c	29 Nov 2007 22:13:35 -0000
***************
*** 7549,7554 ****
--- 7549,7555 ----
      if (evaluate && error == ERROR_NONE)
      {
  	rettv->v_type = VAR_NUMBER;	/* default is number rettv */
+ 	rettv->vval.v_number = 0;       /* default value is 0 (what else?) */
  	error = ERROR_UNKNOWN;
  
  	if (!builtin_function(fname))

Raspunde prin e-mail lui