Blame SOURCES/7.4.624

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.624
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.624
22c937
Problem:    May leak memory or crash when vim_realloc() returns NULL.
22c937
Solution:   Handle a NULL value properly. (Mike Williams)
22c937
Files:	    src/if_cscope.c, src/memline.c, src/misc1.c, src/netbeans.c
22c937
22c937
22c937
*** ../vim-7.4.623/src/if_cscope.c	2014-12-13 03:20:10.539067382 +0100
22c937
--- src/if_cscope.c	2015-02-10 18:33:14.764816257 +0100
22c937
***************
22c937
*** 1507,1515 ****
22c937
--- 1507,1522 ----
22c937
  	}
22c937
  	else
22c937
  	{
22c937
+ 	    csinfo_T *t_csinfo = csinfo;
22c937
+ 
22c937
  	    /* Reallocate space for more connections. */
22c937
  	    csinfo_size *= 2;
22c937
  	    csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size);
22c937
+ 	    if (csinfo == NULL)
22c937
+ 	    {
22c937
+ 		vim_free(t_csinfo);
22c937
+ 		csinfo_size = 0;
22c937
+ 	    }
22c937
  	}
22c937
  	if (csinfo == NULL)
22c937
  	    return -1;
22c937
***************
22c937
*** 2059,2064 ****
22c937
--- 2066,2072 ----
22c937
      int num_matches;
22c937
  {
22c937
      char	*buf = NULL;
22c937
+     char	*t_buf;
22c937
      int		bufsize = 0; /* Track available bufsize */
22c937
      int		newsize = 0;
22c937
      char	*ptag;
22c937
***************
22c937
*** 2120,2128 ****
22c937
--- 2128,2140 ----
22c937
  	newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno));
22c937
  	if (bufsize < newsize)
22c937
  	{
22c937
+ 	    t_buf = buf;
22c937
  	    buf = (char *)vim_realloc(buf, newsize);
22c937
  	    if (buf == NULL)
22c937
+ 	    {
22c937
  		bufsize = 0;
22c937
+ 		vim_free(t_buf);
22c937
+ 	    }
22c937
  	    else
22c937
  		bufsize = newsize;
22c937
  	}
22c937
***************
22c937
*** 2143,2151 ****
22c937
--- 2155,2167 ----
22c937
  
22c937
  	if (bufsize < newsize)
22c937
  	{
22c937
+ 	    t_buf = buf;
22c937
  	    buf = (char *)vim_realloc(buf, newsize);
22c937
  	    if (buf == NULL)
22c937
+ 	    {
22c937
  		bufsize = 0;
22c937
+ 		vim_free(t_buf);
22c937
+ 	    }
22c937
  	    else
22c937
  		bufsize = newsize;
22c937
  	}
22c937
*** ../vim-7.4.623/src/memline.c	2014-08-13 21:58:24.824885492 +0200
22c937
--- src/memline.c	2015-02-10 18:26:23.158126542 +0100
22c937
***************
22c937
*** 5057,5062 ****
22c937
--- 5057,5064 ----
22c937
  	/* May resize here so we don't have to do it in both cases below */
22c937
  	if (buf->b_ml.ml_usedchunks + 1 >= buf->b_ml.ml_numchunks)
22c937
  	{
22c937
+ 	    chunksize_T *t_chunksize = buf->b_ml.ml_chunksize;
22c937
+ 
22c937
  	    buf->b_ml.ml_numchunks = buf->b_ml.ml_numchunks * 3 / 2;
22c937
  	    buf->b_ml.ml_chunksize = (chunksize_T *)
22c937
  		vim_realloc(buf->b_ml.ml_chunksize,
22c937
***************
22c937
*** 5064,5069 ****
22c937
--- 5066,5072 ----
22c937
  	    if (buf->b_ml.ml_chunksize == NULL)
22c937
  	    {
22c937
  		/* Hmmmm, Give up on offset for this buffer */
22c937
+ 		vim_free(t_chunksize);
22c937
  		buf->b_ml.ml_usedchunks = -1;
22c937
  		return;
22c937
  	    }
22c937
*** ../vim-7.4.623/src/misc1.c	2014-08-29 12:58:38.246430208 +0200
22c937
--- src/misc1.c	2015-02-10 18:26:35.405968505 +0100
22c937
***************
22c937
*** 3431,3440 ****
22c937
--- 3431,3444 ----
22c937
  	    buf = alloc(buflen);
22c937
  	else if (maxlen < 10)
22c937
  	{
22c937
+ 	    char_u  *t_buf = buf;
22c937
+ 
22c937
  	    /* Need some more space. This might happen when receiving a long
22c937
  	     * escape sequence. */
22c937
  	    buflen += 100;
22c937
  	    buf = vim_realloc(buf, buflen);
22c937
+ 	    if (buf == NULL)
22c937
+ 		vim_free(t_buf);
22c937
  	    maxlen = (buflen - 6 - len) / 3;
22c937
  	}
22c937
  	if (buf == NULL)
22c937
*** ../vim-7.4.623/src/netbeans.c	2014-03-23 15:12:29.927264336 +0100
22c937
--- src/netbeans.c	2015-02-10 18:27:18.693409965 +0100
22c937
***************
22c937
*** 1080,1089 ****
22c937
--- 1080,1097 ----
22c937
      {
22c937
  	if (bufno >= buf_list_size) /* grow list */
22c937
  	{
22c937
+ 	    nbbuf_T *t_buf_list = buf_list;
22c937
+ 
22c937
  	    incr = bufno - buf_list_size + 90;
22c937
  	    buf_list_size += incr;
22c937
  	    buf_list = (nbbuf_T *)vim_realloc(
22c937
  				   buf_list, buf_list_size * sizeof(nbbuf_T));
22c937
+ 	    if (buf_list == NULL)
22c937
+ 	    {
22c937
+ 		vim_free(t_buf_list);
22c937
+ 		buf_list_size = 0;
22c937
+ 		return NULL;
22c937
+ 	    }
22c937
  	    vim_memset(buf_list + buf_list_size - incr, 0,
22c937
  						      incr * sizeof(nbbuf_T));
22c937
  	}
22c937
***************
22c937
*** 3678,3688 ****
22c937
--- 3686,3703 ----
22c937
  	    {
22c937
  		int incr;
22c937
  		int oldlen = globalsignmaplen;
22c937
+ 		char **t_globalsignmap = globalsignmap;
22c937
  
22c937
  		globalsignmaplen *= 2;
22c937
  		incr = globalsignmaplen - oldlen;
22c937
  		globalsignmap = (char **)vim_realloc(globalsignmap,
22c937
  					   globalsignmaplen * sizeof(char *));
22c937
+ 		if (globalsignmap == NULL)
22c937
+ 		{
22c937
+ 		    vim_free(t_globalsignmap);
22c937
+ 		    globalsignmaplen = 0;
22c937
+ 		    return;
22c937
+ 		}
22c937
  		vim_memset(globalsignmap + oldlen, 0, incr * sizeof(char *));
22c937
  	    }
22c937
  	}
22c937
***************
22c937
*** 3708,3718 ****
22c937
--- 3723,3740 ----
22c937
  	{
22c937
  	    int incr;
22c937
  	    int oldlen = buf->signmaplen;
22c937
+ 	    int *t_signmap = buf->signmap;
22c937
  
22c937
  	    buf->signmaplen *= 2;
22c937
  	    incr = buf->signmaplen - oldlen;
22c937
  	    buf->signmap = (int *)vim_realloc(buf->signmap,
22c937
  					       buf->signmaplen * sizeof(int));
22c937
+ 	    if (buf->signmap == NULL)
22c937
+ 	    {
22c937
+ 		vim_free(t_signmap);
22c937
+ 		buf->signmaplen = 0;
22c937
+ 		return;
22c937
+ 	    }
22c937
  	    vim_memset(buf->signmap + oldlen, 0, incr * sizeof(int));
22c937
  	}
22c937
      }
22c937
*** ../vim-7.4.623/src/version.c	2015-02-10 18:18:13.004452406 +0100
22c937
--- src/version.c	2015-02-10 18:21:29.697913596 +0100
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     624,
22c937
  /**/
22c937
22c937
-- 
22c937
hundred-and-one symptoms of being an internet addict:
22c937
211. Your husband leaves you...taking the computer with him and you
22c937
     call him crying, and beg him to bring the computer back.
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///