657f608
To: vim_dev@googlegroups.com
657f608
Subject: Patch 7.3.148
657f608
Fcc: outbox
657f608
From: Bram Moolenaar <Bram@moolenaar.net>
657f608
Mime-Version: 1.0
657f608
Content-Type: text/plain; charset=UTF-8
657f608
Content-Transfer-Encoding: 8bit
657f608
------------
657f608
657f608
Patch 7.3.148
657f608
Problem:    A syntax file with a huge number of items or clusters causes weird
657f608
	    behavior, a hang or a crash. (Yukihiro Nakadaira)
657f608
Solution:   Check running out of IDs. (partly by Ben Schmidt)
657f608
Files:	    src/syntax.c
657f608
657f608
657f608
*** ../vim-7.3.147/src/syntax.c	2011-01-22 00:58:15.000000000 +0100
657f608
--- src/syntax.c	2011-04-01 14:25:39.000000000 +0200
657f608
***************
657f608
*** 219,234 ****
657f608
  
657f608
  /*
657f608
   * Syntax group IDs have different types:
657f608
!  *     0 -  9999  normal syntax groups
657f608
!  * 10000 - 14999  ALLBUT indicator (current_syn_inc_tag added)
657f608
!  * 15000 - 19999  TOP indicator (current_syn_inc_tag added)
657f608
!  * 20000 - 24999  CONTAINED indicator (current_syn_inc_tag added)
657f608
!  * >= 25000	  cluster IDs (subtract SYNID_CLUSTER for the cluster ID)
657f608
!  */
657f608
! #define SYNID_ALLBUT	10000	    /* syntax group ID for contains=ALLBUT */
657f608
! #define SYNID_TOP	15000	    /* syntax group ID for contains=TOP */
657f608
! #define SYNID_CONTAINED	20000	    /* syntax group ID for contains=CONTAINED */
657f608
! #define SYNID_CLUSTER	25000	    /* first syntax group ID for clusters */
657f608
  
657f608
  /*
657f608
   * Annoying Hack(TM):  ":syn include" needs this pointer to pass to
657f608
--- 219,238 ----
657f608
  
657f608
  /*
657f608
   * Syntax group IDs have different types:
657f608
!  *     0 - 19999  normal syntax groups
657f608
!  * 20000 - 20999  ALLBUT indicator (current_syn_inc_tag added)
657f608
!  * 21000 - 21999  TOP indicator (current_syn_inc_tag added)
657f608
!  * 22000 - 22999  CONTAINED indicator (current_syn_inc_tag added)
657f608
!  * 23000 - 32767  cluster IDs (subtract SYNID_CLUSTER for the cluster ID)
657f608
!  */
657f608
! #define SYNID_ALLBUT	20000	    /* syntax group ID for contains=ALLBUT */
657f608
! #define SYNID_TOP	21000	    /* syntax group ID for contains=TOP */
657f608
! #define SYNID_CONTAINED	22000	    /* syntax group ID for contains=CONTAINED */
657f608
! #define SYNID_CLUSTER	23000	    /* first syntax group ID for clusters */
657f608
! 
657f608
! #define MAX_SYNID       SYNID_ALLBUT
657f608
! #define MAX_SYN_INC_TAG	999	    /* maximum before the above overflow */
657f608
! #define MAX_CLUSTER_ID  (32767 - SYNID_CLUSTER)
657f608
  
657f608
  /*
657f608
   * Annoying Hack(TM):  ":syn include" needs this pointer to pass to
657f608
***************
657f608
*** 3442,3447 ****
657f608
--- 3446,3454 ----
657f608
      /* free the stored states */
657f608
      syn_stack_free_all(block);
657f608
      invalidate_current_state();
657f608
+ 
657f608
+     /* Reset the counter for ":syn include" */
657f608
+     running_syn_inc_tag = 0;
657f608
  }
657f608
  
657f608
  /*
657f608
***************
657f608
*** 4661,4666 ****
657f608
--- 4668,4675 ----
657f608
  	    return;
657f608
  	}
657f608
  	sgl_id = syn_check_cluster(arg, (int)(group_name_end - arg));
657f608
+ 	if (sgl_id == 0)
657f608
+ 	    return;
657f608
  	/* separate_nextcmd() and expand_filename() depend on this */
657f608
  	eap->arg = rest;
657f608
      }
657f608
***************
657f608
*** 4689,4694 ****
657f608
--- 4698,4708 ----
657f608
       * Save and restore the existing top-level grouplist id and ":syn
657f608
       * include" tag around the actual inclusion.
657f608
       */
657f608
+     if (running_syn_inc_tag >= MAX_SYN_INC_TAG)
657f608
+     {
657f608
+ 	EMSG((char_u *)_("E847: Too many syntax includes"));
657f608
+ 	return;
657f608
+     }
657f608
      prev_syn_inc_tag = current_syn_inc_tag;
657f608
      current_syn_inc_tag = ++running_syn_inc_tag;
657f608
      prev_toplvl_grp = curwin->w_s->b_syn_topgrp;
657f608
***************
657f608
*** 4712,4718 ****
657f608
      char_u	*group_name_end;
657f608
      int		syn_id;
657f608
      char_u	*rest;
657f608
!     char_u	*keyword_copy;
657f608
      char_u	*p;
657f608
      char_u	*kw;
657f608
      syn_opt_arg_T syn_opt_arg;
657f608
--- 4726,4732 ----
657f608
      char_u	*group_name_end;
657f608
      int		syn_id;
657f608
      char_u	*rest;
657f608
!     char_u	*keyword_copy = NULL;
657f608
      char_u	*p;
657f608
      char_u	*kw;
657f608
      syn_opt_arg_T syn_opt_arg;
657f608
***************
657f608
*** 4724,4732 ****
657f608
      if (rest != NULL)
657f608
      {
657f608
  	syn_id = syn_check_group(arg, (int)(group_name_end - arg));
657f608
! 
657f608
! 	/* allocate a buffer, for removing the backslashes in the keyword */
657f608
! 	keyword_copy = alloc((unsigned)STRLEN(rest) + 1);
657f608
  	if (keyword_copy != NULL)
657f608
  	{
657f608
  	    syn_opt_arg.flags = 0;
657f608
--- 4738,4746 ----
657f608
      if (rest != NULL)
657f608
      {
657f608
  	syn_id = syn_check_group(arg, (int)(group_name_end - arg));
657f608
! 	if (syn_id != 0)
657f608
! 	    /* allocate a buffer, for removing backslashes in the keyword */
657f608
! 	    keyword_copy = alloc((unsigned)STRLEN(rest) + 1);
657f608
  	if (keyword_copy != NULL)
657f608
  	{
657f608
  	    syn_opt_arg.flags = 0;
657f608
***************
657f608
*** 5133,5139 ****
657f608
  			    (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id;
657f608
! 		    SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = current_syn_inc_tag;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id =
657f608
  							ppp->pp_matchgroup_id;
657f608
  #ifdef FEAT_CONCEAL
657f608
--- 5147,5154 ----
657f608
  			    (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = syn_id;
657f608
! 		    SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag =
657f608
! 							  current_syn_inc_tag;
657f608
  		    SYN_ITEMS(curwin->w_s)[idx].sp_syn_match_id =
657f608
  							ppp->pp_matchgroup_id;
657f608
  #ifdef FEAT_CONCEAL
657f608
***************
657f608
*** 5426,5431 ****
657f608
--- 5441,5454 ----
657f608
  	curwin->w_s->b_syn_clusters.ga_growsize = 10;
657f608
      }
657f608
  
657f608
+     len = curwin->w_s->b_syn_clusters.ga_len;
657f608
+     if (len >= MAX_CLUSTER_ID)
657f608
+     {
657f608
+ 	EMSG((char_u *)_("E848: Too many syntax clusters"));
657f608
+ 	vim_free(name);
657f608
+ 	return 0;
657f608
+     }
657f608
+ 
657f608
      /*
657f608
       * Make room for at least one other cluster entry.
657f608
       */
657f608
***************
657f608
*** 5434,5440 ****
657f608
  	vim_free(name);
657f608
  	return 0;
657f608
      }
657f608
-     len = curwin->w_s->b_syn_clusters.ga_len;
657f608
  
657f608
      vim_memset(&(SYN_CLSTR(curwin->w_s)[len]), 0, sizeof(syn_cluster_T));
657f608
      SYN_CLSTR(curwin->w_s)[len].scl_name = name;
657f608
--- 5457,5462 ----
657f608
***************
657f608
*** 5476,5483 ****
657f608
  
657f608
      if (rest != NULL)
657f608
      {
657f608
! 	scl_id = syn_check_cluster(arg, (int)(group_name_end - arg))
657f608
! 							      - SYNID_CLUSTER;
657f608
  
657f608
  	for (;;)
657f608
  	{
657f608
--- 5498,5507 ----
657f608
  
657f608
      if (rest != NULL)
657f608
      {
657f608
! 	scl_id = syn_check_cluster(arg, (int)(group_name_end - arg));
657f608
! 	if (scl_id == 0)
657f608
! 	    return;
657f608
! 	scl_id -= SYNID_CLUSTER;
657f608
  
657f608
  	for (;;)
657f608
  	{
657f608
***************
657f608
*** 5516,5522 ****
657f608
  	if (got_clstr)
657f608
  	{
657f608
  	    redraw_curbuf_later(SOME_VALID);
657f608
! 	    syn_stack_free_all(curwin->w_s);	/* Need to recompute all syntax. */
657f608
  	}
657f608
      }
657f608
  
657f608
--- 5540,5546 ----
657f608
  	if (got_clstr)
657f608
  	{
657f608
  	    redraw_curbuf_later(SOME_VALID);
657f608
! 	    syn_stack_free_all(curwin->w_s);	/* Need to recompute all. */
657f608
  	}
657f608
      }
657f608
  
657f608
***************
657f608
*** 8972,8977 ****
657f608
--- 8996,9008 ----
657f608
  	highlight_ga.ga_growsize = 10;
657f608
      }
657f608
  
657f608
+     if (highlight_ga.ga_len >= MAX_SYNID)
657f608
+     {
657f608
+ 	EMSG(_("E849: Too many syntax groups"));
657f608
+ 	vim_free(name);
657f608
+ 	return 0;
657f608
+     }
657f608
+ 
657f608
      /*
657f608
       * Make room for at least one other syntax_highlight entry.
657f608
       */
657f608
*** ../vim-7.3.147/src/version.c	2011-04-01 13:05:37.000000000 +0200
657f608
--- src/version.c	2011-04-01 14:26:44.000000000 +0200
657f608
***************
657f608
*** 716,717 ****
657f608
--- 716,719 ----
657f608
  {   /* Add new patch number below this line */
657f608
+ /**/
657f608
+     148,
657f608
  /**/
657f608
657f608
-- 
657f608
BLACK KNIGHT: None shall pass.
657f608
ARTHUR:       I have no quarrel with you, brave Sir knight, but I must cross
657f608
              this bridge.
657f608
BLACK KNIGHT: Then you shall die.
657f608
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
657f608
657f608
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
657f608
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
657f608
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
657f608
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///