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