home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.2 / 7.2.440 < prev    next >
Encoding:
Internet Message Format  |  2010-05-27  |  5.7 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 7.2.440
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.2.440
  11. Problem:    Calling a function through a funcref, where the function deletes
  12.         the funcref, leads to an invalid memory access.
  13. Solution:   Make a copy of the function name. (Lech Lorens)
  14. Files:        src/eval.c, src/testdir/test34.in, src/testdir/test34.ok
  15.  
  16.  
  17. *** ../vim-7.2.439/src/eval.c    2010-05-16 13:26:19.000000000 +0200
  18. --- src/eval.c    2010-05-28 22:01:07.000000000 +0200
  19. ***************
  20. *** 464,470 ****
  21.   static int find_internal_func __ARGS((char_u *name));
  22.   static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
  23.   static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
  24. ! static int call_func __ARGS((char_u *name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
  25.   static void emsg_funcname __ARGS((char *ermsg, char_u *name));
  26.   static int non_zero_arg __ARGS((typval_T *argvars));
  27.   
  28. --- 464,470 ----
  29.   static int find_internal_func __ARGS((char_u *name));
  30.   static char_u *deref_func_name __ARGS((char_u *name, int *lenp));
  31.   static int get_func_tv __ARGS((char_u *name, int len, typval_T *rettv, char_u **arg, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
  32. ! static int call_func __ARGS((char_u *func_name, int len, typval_T *rettv, int argcount, typval_T *argvars, linenr_T firstline, linenr_T lastline, int *doesrange, int evaluate, dict_T *selfdict));
  33.   static void emsg_funcname __ARGS((char *ermsg, char_u *name));
  34.   static int non_zero_arg __ARGS((typval_T *argvars));
  35.   
  36. ***************
  37. *** 7997,8005 ****
  38.    * Also returns OK when an error was encountered while executing the function.
  39.    */
  40.       static int
  41. ! call_func(name, len, rettv, argcount, argvars, firstline, lastline,
  42.                           doesrange, evaluate, selfdict)
  43. !     char_u    *name;        /* name of the function */
  44.       int        len;        /* length of "name" */
  45.       typval_T    *rettv;        /* return value goes here */
  46.       int        argcount;    /* number of "argvars" */
  47. --- 7997,8005 ----
  48.    * Also returns OK when an error was encountered while executing the function.
  49.    */
  50.       static int
  51. ! call_func(func_name, len, rettv, argcount, argvars, firstline, lastline,
  52.                           doesrange, evaluate, selfdict)
  53. !     char_u    *func_name;    /* name of the function */
  54.       int        len;        /* length of "name" */
  55.       typval_T    *rettv;        /* return value goes here */
  56.       int        argcount;    /* number of "argvars" */
  57. ***************
  58. *** 8023,8040 ****
  59.       int        i;
  60.       int        llen;
  61.       ufunc_T    *fp;
  62. -     int        cc;
  63.   #define FLEN_FIXED 40
  64.       char_u    fname_buf[FLEN_FIXED + 1];
  65.       char_u    *fname;
  66.   
  67.       /*
  68.        * In a script change <SID>name() and s:name() to K_SNR 123_name().
  69.        * Change <SNR>123_name() to K_SNR 123_name().
  70.        * Use fname_buf[] when it fits, otherwise allocate memory (slow).
  71.        */
  72. -     cc = name[len];
  73. -     name[len] = NUL;
  74.       llen = eval_fname_script(name);
  75.       if (llen > 0)
  76.       {
  77. --- 8023,8044 ----
  78.       int        i;
  79.       int        llen;
  80.       ufunc_T    *fp;
  81.   #define FLEN_FIXED 40
  82.       char_u    fname_buf[FLEN_FIXED + 1];
  83.       char_u    *fname;
  84. +     char_u    *name;
  85. +     /* Make a copy of the name, if it comes from a funcref variable it could
  86. +      * be changed or deleted in the called function. */
  87. +     name = vim_strnsave(func_name, len);
  88. +     if (name == NULL)
  89. +     return ret;
  90.   
  91.       /*
  92.        * In a script change <SID>name() and s:name() to K_SNR 123_name().
  93.        * Change <SNR>123_name() to K_SNR 123_name().
  94.        * Use fname_buf[] when it fits, otherwise allocate memory (slow).
  95.        */
  96.       llen = eval_fname_script(name);
  97.       if (llen > 0)
  98.       {
  99. ***************
  100. *** 8205,8213 ****
  101.       }
  102.       }
  103.   
  104. -     name[len] = cc;
  105.       if (fname != name && fname != fname_buf)
  106.       vim_free(fname);
  107.   
  108.       return ret;
  109.   }
  110. --- 8209,8217 ----
  111.       }
  112.       }
  113.   
  114.       if (fname != name && fname != fname_buf)
  115.       vim_free(fname);
  116. +     vim_free(name);
  117.   
  118.       return ret;
  119.   }
  120. *** ../vim-7.2.439/src/testdir/test34.in    2007-09-25 17:59:15.000000000 +0200
  121. --- src/testdir/test34.in    2010-05-28 21:54:36.000000000 +0200
  122. ***************
  123. *** 35,40 ****
  124. --- 35,45 ----
  125.   :  let g:counter = 0
  126.   :  return ''
  127.   :endfunc
  128. + :func FuncWithRef(a)
  129. + :  unlet g:FuncRef
  130. + :  return a:a
  131. + :endfunc
  132. + :let g:FuncRef=function("FuncWithRef")
  133.   :let counter = 0
  134.   :inoremap <expr> ( ListItem()
  135.   :inoremap <expr> [ ListReset()
  136. ***************
  137. *** 47,52 ****
  138. --- 52,58 ----
  139.    =retval
  140.    =Compute(45, 5, "retval")
  141.    =retval
  142. +  =g:FuncRef(333)
  143.   
  144.   XX+-XX
  145.   ---*---
  146. *** ../vim-7.2.439/src/testdir/test34.ok    2006-04-30 20:49:40.000000000 +0200
  147. --- src/testdir/test34.ok    2010-05-28 21:56:03.000000000 +0200
  148. ***************
  149. *** 1,4 ****
  150. ! xxx4asdf fail nop ok 9
  151.   XX111XX
  152.   ---222---
  153.   1. one
  154. --- 1,4 ----
  155. ! xxx4asdf fail nop ok 9 333
  156.   XX111XX
  157.   ---222---
  158.   1. one
  159. *** ../vim-7.2.439/src/version.c    2010-05-28 21:31:51.000000000 +0200
  160. --- src/version.c    2010-05-28 22:03:30.000000000 +0200
  161. ***************
  162. *** 683,684 ****
  163. --- 683,686 ----
  164.   {   /* Add new patch number below this line */
  165. + /**/
  166. +     440,
  167.   /**/
  168.  
  169. -- 
  170. Nobody will ever need more than 640 kB RAM.
  171.         -- Bill Gates, 1983
  172. Windows 98 requires 16 MB RAM.
  173.         -- Bill Gates, 1999
  174. Logical conclusion: Nobody will ever need Windows 98.
  175.  
  176.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  177. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  178. \\\        download, build and distribute -- http://www.A-A-P.org        ///
  179.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  180.