99b86a7
To: vim-dev@vim.org
99b86a7
Subject: patch 7.1.087
99b86a7
Fcc: outbox
99b86a7
From: Bram Moolenaar <Bram@moolenaar.net>
99b86a7
Mime-Version: 1.0
99b86a7
Content-Type: text/plain; charset=ISO-8859-1
99b86a7
Content-Transfer-Encoding: 8bit
99b86a7
------------
99b86a7
99b86a7
Patch 7.1.087
99b86a7
Problem:    Reading past ":cscope find" command.  Writing past end of a buffer.
99b86a7
Solution:   Check length of the argument before using the pattern.  Use
99b86a7
	    vim_strncpy().  (Dominique Pelle)
99b86a7
Files:	    if_cscope.c
99b86a7
99b86a7
99b86a7
*** ../vim-7.1.086/src/if_cscope.c	Sun Mar 11 15:48:29 2007
99b86a7
--- src/if_cscope.c	Sun Aug 19 22:17:09 2007
99b86a7
***************
99b86a7
*** 73,78 ****
99b86a7
--- 73,80 ----
99b86a7
  
99b86a7
  
99b86a7
  static csinfo_T	    csinfo[CSCOPE_MAX_CONNECTIONS];
99b86a7
+ static int	    eap_arg_len;    /* length of eap->arg, set in
99b86a7
+ 				       cs_lookup_cmd() */
99b86a7
  static cscmd_T	    cs_cmds[] =
99b86a7
  {
99b86a7
      { "add",	cs_add,
99b86a7
***************
99b86a7
*** 260,273 ****
99b86a7
  
99b86a7
      if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL)
99b86a7
  	return TRUE;
99b86a7
! 
99b86a7
!     if ((int)strlen(p) > size)
99b86a7
!     {
99b86a7
! 	strncpy((char *)buf, p, size - 1);
99b86a7
! 	buf[size] = '\0';
99b86a7
!     }
99b86a7
!     else
99b86a7
! 	(void)strcpy((char *)buf, p);
99b86a7
  
99b86a7
      return FALSE;
99b86a7
  } /* cs_fgets */
99b86a7
--- 262,268 ----
99b86a7
  
99b86a7
      if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL)
99b86a7
  	return TRUE;
99b86a7
!     vim_strncpy(buf, (char_u *)p, size - 1);
99b86a7
  
99b86a7
      return FALSE;
99b86a7
  } /* cs_fgets */
99b86a7
***************
99b86a7
*** 386,392 ****
99b86a7
   * PRIVATE: cs_add
99b86a7
   *
99b86a7
   * add cscope database or a directory name (to look for cscope.out)
99b86a7
!  * the the cscope connection list
99b86a7
   *
99b86a7
   * MAXPATHL 256
99b86a7
   */
99b86a7
--- 381,387 ----
99b86a7
   * PRIVATE: cs_add
99b86a7
   *
99b86a7
   * add cscope database or a directory name (to look for cscope.out)
99b86a7
!  * to the cscope connection list
99b86a7
   *
99b86a7
   * MAXPATHL 256
99b86a7
   */
99b86a7
***************
99b86a7
*** 966,972 ****
99b86a7
      }
99b86a7
  
99b86a7
      pat = opt + strlen(opt) + 1;
99b86a7
!     if (pat == NULL || (pat != NULL && pat[0] == '\0'))
99b86a7
      {
99b86a7
  	cs_usage_msg(Find);
99b86a7
  	return FALSE;
99b86a7
--- 961,967 ----
99b86a7
      }
99b86a7
  
99b86a7
      pat = opt + strlen(opt) + 1;
99b86a7
!     if (pat >= (char *)eap->arg + eap_arg_len)
99b86a7
      {
99b86a7
  	cs_usage_msg(Find);
99b86a7
  	return FALSE;
99b86a7
***************
99b86a7
*** 1317,1323 ****
99b86a7
  #else
99b86a7
  	    /* compare pathnames first */
99b86a7
  	    && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
99b86a7
! 		/* if not Windows 9x, test index file atributes too */
99b86a7
  		|| (!mch_windows95()
99b86a7
  		    && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
99b86a7
  		    && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
99b86a7
--- 1312,1318 ----
99b86a7
  #else
99b86a7
  	    /* compare pathnames first */
99b86a7
  	    && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
99b86a7
! 		/* if not Windows 9x, test index file attributes too */
99b86a7
  		|| (!mch_windows95()
99b86a7
  		    && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
99b86a7
  		    && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
99b86a7
***************
99b86a7
*** 1401,1406 ****
99b86a7
--- 1396,1404 ----
99b86a7
      if (eap->arg == NULL)
99b86a7
  	return NULL;
99b86a7
  
99b86a7
+     /* Store length of eap->arg before it gets modified by strtok(). */
99b86a7
+     eap_arg_len = STRLEN(eap->arg);
99b86a7
+ 
99b86a7
      if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
99b86a7
  	return NULL;
99b86a7
  
99b86a7
***************
99b86a7
*** 2195,2201 ****
99b86a7
  	    cs_add_common(dblist[i], pplist[i], fllist[i]);
99b86a7
  	    if (p_csverbose)
99b86a7
  	    {
99b86a7
! 		/* dont' use smsg_attr because want to display
99b86a7
  		 * connection number in the same line as
99b86a7
  		 * "Added cscope database..."
99b86a7
  		 */
99b86a7
--- 2193,2199 ----
99b86a7
  	    cs_add_common(dblist[i], pplist[i], fllist[i]);
99b86a7
  	    if (p_csverbose)
99b86a7
  	    {
99b86a7
! 		/* don't use smsg_attr() because we want to display the
99b86a7
  		 * connection number in the same line as
99b86a7
  		 * "Added cscope database..."
99b86a7
  		 */
99b86a7
*** ../vim-7.1.086/src/version.c	Tue Aug 21 17:29:04 2007
99b86a7
--- src/version.c	Tue Aug 21 17:59:42 2007
99b86a7
***************
99b86a7
*** 668,669 ****
99b86a7
--- 668,671 ----
99b86a7
  {   /* Add new patch number below this line */
99b86a7
+ /**/
99b86a7
+     87,
99b86a7
  /**/
99b86a7
99b86a7
-- 
99b86a7
hundred-and-one symptoms of being an internet addict:
99b86a7
223. You set up a web-cam as your home's security system.
99b86a7
99b86a7
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
99b86a7
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
99b86a7
\\\        download, build and distribute -- http://www.A-A-P.org        ///
99b86a7
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///