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.3 / 7.3.1280 < prev    next >
Encoding:
Internet Message Format  |  2013-06-29  |  6.7 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.1280
  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.3.1280
  11. Problem:    Reading memory already freed since patch 7.3.1247. (Simon
  12.         Ruderich, Dominique Pelle)
  13. Solution:   Copy submatches before reallocating the state list.
  14. Files:        src/regexp_nfa.c
  15.  
  16.  
  17. *** ../vim-7.3.1279/src/regexp_nfa.c    2013-06-30 13:17:18.000000000 +0200
  18. --- src/regexp_nfa.c    2013-06-30 23:17:46.000000000 +0200
  19. ***************
  20. *** 3538,3544 ****
  21.   static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
  22.   static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  23.   static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  24. ! static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int off));
  25.   static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip));
  26.   
  27.   /*
  28. --- 3538,3544 ----
  29.   static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
  30.   static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  31.   static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
  32. ! static regsubs_T *addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs_arg, nfa_pim_T *pim, int off));
  33.   static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip));
  34.   
  35.   /*
  36. ***************
  37. *** 3832,3844 ****
  38.       return FALSE;
  39.   }
  40.   
  41. !     static void
  42. ! addstate(l, state, subs, pim, off)
  43. !     nfa_list_T        *l;    /* runtime state list */
  44. !     nfa_state_T        *state;    /* state to update */
  45. !     regsubs_T        *subs;    /* pointers to subexpressions */
  46. !     nfa_pim_T        *pim;   /* postponed look-behind match */
  47. !     int            off;    /* byte offset, when -1 go to next line */
  48.   {
  49.       int            subidx;
  50.       nfa_thread_T    *thread;
  51. --- 3832,3849 ----
  52.       return FALSE;
  53.   }
  54.   
  55. ! /*
  56. !  * Add "state" and possibly what follows to state list ".".
  57. !  * Returns "subs_arg", possibly copied into temp_subs.
  58. !  */
  59. !     static regsubs_T *
  60. ! addstate(l, state, subs_arg, pim, off)
  61. !     nfa_list_T        *l;        /* runtime state list */
  62. !     nfa_state_T        *state;        /* state to update */
  63. !     regsubs_T        *subs_arg;  /* pointers to subexpressions */
  64. !     nfa_pim_T        *pim;        /* postponed look-behind match */
  65. !     int            off;        /* byte offset, when -1 go to next line */
  66.   {
  67.       int            subidx;
  68.       nfa_thread_T    *thread;
  69. ***************
  70. *** 3847,3852 ****
  71. --- 3852,3859 ----
  72.       char_u        *save_ptr;
  73.       int            i;
  74.       regsub_T        *sub;
  75. +     regsubs_T        *subs = subs_arg;
  76. +     static regsubs_T    temp_subs;
  77.   #ifdef ENABLE_LOG
  78.       int            did_print = FALSE;
  79.   #endif
  80. ***************
  81. *** 3941,3947 ****
  82.               fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s\n",
  83.                   abs(state->id), l->id, state->c, code);
  84.   #endif
  85. !             return;
  86.           }
  87.   
  88.           /* Do not add the state again when it exists with the same
  89. --- 3948,3954 ----
  90.               fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s\n",
  91.                   abs(state->id), l->id, state->c, code);
  92.   #endif
  93. !             return subs;
  94.           }
  95.   
  96.           /* Do not add the state again when it exists with the same
  97. ***************
  98. *** 3956,3961 ****
  99. --- 3963,3980 ----
  100.           {
  101.           int newlen = l->len * 3 / 2 + 50;
  102.   
  103. +         if (subs != &temp_subs)
  104. +         {
  105. +             /* "subs" may point into the current array, need to make a
  106. +              * copy before it becomes invalid. */
  107. +             copy_sub(&temp_subs.norm, &subs->norm);
  108. + #ifdef FEAT_SYN_HL
  109. +             if (nfa_has_zsubexpr)
  110. +             copy_sub(&temp_subs.synt, &subs->synt);
  111. + #endif
  112. +             subs = &temp_subs;
  113. +         }
  114.           l->t = vim_realloc(l->t, newlen * sizeof(nfa_thread_T));
  115.           l->len = newlen;
  116.           }
  117. ***************
  118. *** 3991,4004 ****
  119.   
  120.       case NFA_SPLIT:
  121.           /* order matters here */
  122. !         addstate(l, state->out, subs, pim, off);
  123. !         addstate(l, state->out1, subs, pim, off);
  124.           break;
  125.   
  126.       case NFA_SKIP_CHAR:
  127.       case NFA_NOPEN:
  128.       case NFA_NCLOSE:
  129. !         addstate(l, state->out, subs, pim, off);
  130.           break;
  131.   
  132.       case NFA_MOPEN:
  133. --- 4010,4023 ----
  134.   
  135.       case NFA_SPLIT:
  136.           /* order matters here */
  137. !         subs = addstate(l, state->out, subs, pim, off);
  138. !         subs = addstate(l, state->out1, subs, pim, off);
  139.           break;
  140.   
  141.       case NFA_SKIP_CHAR:
  142.       case NFA_NOPEN:
  143.       case NFA_NCLOSE:
  144. !         subs = addstate(l, state->out, subs, pim, off);
  145.           break;
  146.   
  147.       case NFA_MOPEN:
  148. ***************
  149. *** 4094,4100 ****
  150.           sub->list.line[subidx].start = reginput + off;
  151.           }
  152.   
  153. !         addstate(l, state->out, subs, pim, off);
  154.   
  155.           if (save_in_use == -1)
  156.           {
  157. --- 4113,4119 ----
  158.           sub->list.line[subidx].start = reginput + off;
  159.           }
  160.   
  161. !         subs = addstate(l, state->out, subs, pim, off);
  162.   
  163.           if (save_in_use == -1)
  164.           {
  165. ***************
  166. *** 4112,4118 ****
  167.           {
  168.           /* Do not overwrite the position set by \ze. If no \ze
  169.            * encountered end will be set in nfa_regtry(). */
  170. !         addstate(l, state->out, subs, pim, off);
  171.           break;
  172.           }
  173.       case NFA_MCLOSE1:
  174. --- 4131,4137 ----
  175.           {
  176.           /* Do not overwrite the position set by \ze. If no \ze
  177.            * encountered end will be set in nfa_regtry(). */
  178. !         subs = addstate(l, state->out, subs, pim, off);
  179.           break;
  180.           }
  181.       case NFA_MCLOSE1:
  182. ***************
  183. *** 4181,4187 ****
  184.           sub->list.line[subidx].end = reginput + off;
  185.           }
  186.   
  187. !         addstate(l, state->out, subs, pim, off);
  188.   
  189.           if (REG_MULTI)
  190.           sub->list.multi[subidx].end = save_lpos;
  191. --- 4200,4206 ----
  192.           sub->list.line[subidx].end = reginput + off;
  193.           }
  194.   
  195. !         subs = addstate(l, state->out, subs, pim, off);
  196.   
  197.           if (REG_MULTI)
  198.           sub->list.multi[subidx].end = save_lpos;
  199. ***************
  200. *** 4190,4195 ****
  201. --- 4209,4215 ----
  202.           sub->in_use = save_in_use;
  203.           break;
  204.       }
  205. +     return subs;
  206.   }
  207.   
  208.   /*
  209. *** ../vim-7.3.1279/src/version.c    2013-06-30 22:43:22.000000000 +0200
  210. --- src/version.c    2013-06-30 23:23:02.000000000 +0200
  211. ***************
  212. *** 730,731 ****
  213. --- 730,733 ----
  214.   {   /* Add new patch number below this line */
  215. + /**/
  216. +     1280,
  217.   /**/
  218.  
  219. -- 
  220. DENNIS:  Listen -- strange women lying in ponds distributing swords is no
  221.          basis for a system of government.  Supreme executive power derives
  222.          from a mandate from the masses, not from some farcical aquatic
  223.          ceremony.
  224.                                   The Quest for the Holy Grail (Monty Python)
  225.  
  226.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  227. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  228. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  229.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  230.