🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #1189

tar 1.11.1: more allocations without checking return value

#1189
From: Jonathan I. Kamens
Date: Wed, 30 Dec 1992 11:09
239 lines
8001 bytes
There are a number of places where memory is allocated without
checking its return value.

*** 1.1	1992/12/30 20:58:42
--- create.c	1992/12/30 21:04:49
***************
*** 943,949 ****
  	/* 
  	 * Make room for our scratch space -- initially is 10 elts long
  	 */
! 	sparsearray = (struct sp_array *) malloc(sp_array_size * sizeof(struct sp_array));
  	for (i = 0; i < sp_array_size; i++) {
  		sparsearray[i].offset = 0;
  		sparsearray[i].numbytes = 0;
--- 943,949 ----
  	/* 
  	 * Make room for our scratch space -- initially is 10 elts long
  	 */
! 	sparsearray = (struct sp_array *) ck_malloc(sp_array_size * sizeof(struct sp_array));
  	for (i = 0; i < sp_array_size; i++) {
  		sparsearray[i].offset = 0;
  		sparsearray[i].numbytes = 0;
***************
*** 1006,1012 ****
  		 * realloc the scratch area, since we've run out of room --
  		 */
  			sparsearray = (struct sp_array *) 
! 					realloc(sparsearray,
   						2 * sp_array_size * (sizeof(struct sp_array)));
  			sp_array_size *= 2;
  		}
--- 1006,1012 ----
  		 * realloc the scratch area, since we've run out of room --
  		 */
  			sparsearray = (struct sp_array *) 
! 					ck_realloc(sparsearray,
   						2 * sp_array_size * (sizeof(struct sp_array)));
  			sp_array_size *= 2;
  		}
*** 1.1	1992/12/30 21:06:47
--- diffarch.c	1992/12/30 21:04:48
***************
*** 542,548 ****
  /*	int		amt_read = 0;*/
  	int		size = filesize;
  
! 	buf = (char *) malloc(buf_size * sizeof (char));
  	
  	fill_in_sparse_array();
  	
--- 542,548 ----
  /*	int		amt_read = 0;*/
  	int		size = filesize;
  
! 	buf = (char *) ck_malloc(buf_size * sizeof (char));
  	
  	fill_in_sparse_array();
  	
***************
*** 563,569 ****
  		 * take care to not run out of room in our buffer
  		 */
  		while (buf_size < numbytes) {
! 			buf = (char *) realloc(buf, buf_size * 2 * sizeof(char));
  			buf_size *= 2;
  		}
  		while (numbytes > RECORDSIZE) {
--- 563,569 ----
  		 * take care to not run out of room in our buffer
  		 */
  		while (buf_size < numbytes) {
! 			buf = (char *) ck_realloc(buf, buf_size * 2 * sizeof(char));
  			buf_size *= 2;
  		}
  		while (numbytes > RECORDSIZE) {
***************
*** 641,647 ****
  	 * necessary
  	 */
  	sp_array_size = 10;
! 	sparsearray = (struct sp_array *) malloc(sp_array_size * sizeof(struct sp_array));
  
  	/*
  	 * there are at most five of these structures in the header
--- 641,647 ----
  	 * necessary
  	 */
  	sp_array_size = 10;
! 	sparsearray = (struct sp_array *) ck_malloc(sp_array_size * sizeof(struct sp_array));
  
  	/*
  	 * there are at most five of these structures in the header
***************
*** 673,679 ****
  				 *  scratch area - realloc it
   				 */
  				sparsearray = (struct sp_array *)
! 					realloc(sparsearray, 
  						sp_array_size*2*sizeof(struct sp_array));
  				sp_array_size *= 2;
  			}
--- 673,679 ----
  				 *  scratch area - realloc it
   				 */
  				sparsearray = (struct sp_array *)
! 					ck_realloc(sparsearray, 
  						sp_array_size*2*sizeof(struct sp_array));
  				sp_array_size *= 2;
  			}
*** 1.1	1992/12/30 21:06:12
--- extract.c	1992/12/30 21:04:48
***************
*** 213,219 ****
  	  */
  	 case LF_SPARSE:
  		 sp_array_size = 10;
! 		 sparsearray = (struct sp_array *) malloc(sp_array_size * sizeof(struct sp_array));
  		 for (i = 0; i < SPARSE_IN_HDR; i++) {
  			 sparsearray[i].offset = 
  				 from_oct(1+12, head->header.sp[i].offset);
--- 213,219 ----
  	  */
  	 case LF_SPARSE:
  		 sp_array_size = 10;
! 		 sparsearray = (struct sp_array *) ck_malloc(sp_array_size * sizeof(struct sp_array));
  		 for (i = 0; i < SPARSE_IN_HDR; i++) {
  			 sparsearray[i].offset = 
  				 from_oct(1+12, head->header.sp[i].offset);
***************
*** 243,249 ****
  					  * since we've run out of room --
  					  */
  						 sparsearray = (struct sp_array *) 
! 								 realloc(sparsearray,
  								 2 * sp_array_size * (sizeof(struct sp_array)));
  						 sp_array_size *= 2;
  					 }
--- 243,249 ----
  					  * since we've run out of room --
  					  */
  						 sparsearray = (struct sp_array *) 
! 								 ck_realloc(sparsearray,
  								 2 * sp_array_size * (sizeof(struct sp_array)));
  						 sp_array_size *= 2;
  					 }
***************
*** 355,361 ****
  			  * REAL interesting unless we do this.
  			  */
  			 namelen = strlen(skipcrud + current_file_name);
! 			 name = (char *) malloc((sizeof(char)) * namelen);
  			 bcopy(skipcrud+current_file_name, name, namelen);
  			 size = hstat.st_size;
  			 extract_sparse_file(fd, &size, hstat.st_size, name);
--- 355,361 ----
  			  * REAL interesting unless we do this.
  			  */
  			 namelen = strlen(skipcrud + current_file_name);
! 			 name = (char *) ck_malloc((sizeof(char)) * namelen);
  			 bcopy(skipcrud+current_file_name, name, namelen);
  			 size = hstat.st_size;
  			 extract_sparse_file(fd, &size, hstat.st_size, name);
***************
*** 652,659 ****
  
  		if (f_modified)
  		  goto set_filestat;
! 		tmp = (struct saved_dir_info *) malloc (sizeof (struct saved_dir_info));
! 		tmp->path = malloc (strlen (skipcrud + current_file_name) + 1);
  		strcpy (tmp->path, skipcrud + current_file_name);
  		tmp->mode = hstat.st_mode;
  		tmp->atime = hstat.st_atime;
--- 652,659 ----
  
  		if (f_modified)
  		  goto set_filestat;
! 		tmp = (struct saved_dir_info *) ck_malloc (sizeof (struct saved_dir_info));
! 		tmp->path = ck_malloc (strlen (skipcrud + current_file_name) + 1);
  		strcpy (tmp->path, skipcrud + current_file_name);
  		tmp->mode = hstat.st_mode;
  		tmp->atime = hstat.st_atime;
*** 1.1	1992/12/30 21:01:17
--- list.c	1992/12/30 21:04:47
***************
*** 387,393 ****
  		    : head->header.arch_name);
  	    if (current_file_name)
  	      free (current_file_name);
! 	    current_file_name = malloc (strlen (name) + 1);
  	    strcpy (current_file_name, name);
  
  	    name = (next_long_link
--- 387,393 ----
  		    : head->header.arch_name);
  	    if (current_file_name)
  	      free (current_file_name);
! 	    current_file_name = ck_malloc (strlen (name) + 1);
  	    strcpy (current_file_name, name);
  
  	    name = (next_long_link
***************
*** 395,401 ****
  		    : head->header.arch_linkname);
  	    if (current_link_name)
  	      free (current_link_name);
! 	    current_link_name = malloc (strlen (name) + 1);
  	    strcpy (current_link_name, name);
  	    
  	    next_long_link = next_long_name = 0;
--- 395,401 ----
  		    : head->header.arch_linkname);
  	    if (current_link_name)
  	      free (current_link_name);
! 	    current_link_name = ck_malloc (strlen (name) + 1);
  	    strcpy (current_link_name, name);
  	    
  	    next_long_link = next_long_name = 0;
*** 1.2	1992/12/14 18:46:23
--- tar.c	1992/12/30 21:04:46
***************
*** 304,310 ****
  
  	/* Set default option values */
  	blocking = DEFBLOCKING;		/* From Makefile */
! 	ar_files = (char **) malloc (sizeof (char *) * 10);
  	ar_files_len = 10;
  	n_ar_files = 0;
  	cur_ar_file = 0;
--- 304,310 ----
  
  	/* Set default option values */
  	blocking = DEFBLOCKING;		/* From Makefile */
! 	ar_files = (char **) ck_malloc (sizeof (char *) * 10);
  	ar_files_len = 10;
  	n_ar_files = 0;
  	cur_ar_file = 0;

Jonathan Kamens                                         jik@MIT.Edu
Aktis, Inc.                                 Moderator, news.answers
Technical Details
Message-ID: <9212302109.AA10686@pad-thai.aktis.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!aktis.COM!jik

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!aktis.COM!jik
From: jik@aktis.COM (Jonathan I. Kamens)
Subject: tar 1.11.1: more allocations without checking return value
Message-ID: <9212302109.AA10686@pad-thai.aktis.com>
Sender: gnulists@ai.mit.edu
Organization: Gnus Not Usenet
Distribution: gnu
Date: Wed, 30 Dec 1992 11:09:26 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 240