Loading ...
Sorry, an error occurred while loading the content.

48582Re: Error when opening Perl file with 'filetype plugin on' + restricted mode (-Z)

Expand Messages
  • Bram Moolenaar
    Nov 30, 2007
    • 0 Attachment
      Dominique Pelle wrote:

      > 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.

      I think the simplest is to use a try/catch:

      *** ../vim-7.1.164/runtime/ftplugin/perl.vim Fri Dec 16 22:51:53 2005
      --- runtime/ftplugin/perl.vim Fri Nov 30 20:53:11 2007
      ***************
      *** 42,53 ****
      --- 42,57 ----
      " Set this once, globally.
      if !exists("perlpath")
      if executable("perl")
      + try
      if &shellxquote != '"'
      let perlpath = system('perl -e "print join(q/,/,@INC)"')
      else
      let perlpath = system("perl -e 'print join(q/,/,@INC)'")
      endif
      let perlpath = substitute(perlpath,',.$',',,','')
      + catch /E145:/
      + let perlpath = ".,,"
      + endtry
      else
      " If we can't call perl to get its path, just default to using the
      " current directory and the directory of the current file.


      > 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.

      It also happens for the man.vim plugin.

      > 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?

      The idea is that every function should set the return value.
      f_system() doesn't do this in a couple of situations. It's easy to fix
      this:

      *** ../vim-7.1.164/src/eval.c Thu Nov 8 20:47:34 2007
      --- src/eval.c Fri Nov 30 21:01:26 2007
      ***************
      *** 15826,15832 ****
      FILE *fd;

      if (check_restricted() || check_secure())
      ! return;

      if (argvars[1].v_type != VAR_UNKNOWN)
      {
      --- 15826,15832 ----
      FILE *fd;

      if (check_restricted() || check_secure())
      ! goto done;

      if (argvars[1].v_type != VAR_UNKNOWN)
      {
      ***************
      *** 15837,15843 ****
      if ((infile = vim_tempname('i')) == NULL)
      {
      EMSG(_(e_notmp));
      ! return;
      }

      fd = mch_fopen((char *)infile, WRITEBIN);
      --- 15837,15843 ----
      if ((infile = vim_tempname('i')) == NULL)
      {
      EMSG(_(e_notmp));
      ! goto done;
      }

      fd = mch_fopen((char *)infile, WRITEBIN);


      --
      hundred-and-one symptoms of being an internet addict:
      164. You got out to buy software, instead of going out for a beer.

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ download, build and distribute -- http://www.A-A-P.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Show all 2 messages in this topic