bug in newform

wescott at sauron.UUCP wescott at sauron.UUCP
Wed Sep 10 07:05:42 AEST 1986


The newform(1) program gracelessly dumps core if you feed it a long
enough line.  Patch is below.  The fix truncates input at NCOLS (512)
characters.

Your line numbers will differ:

*** newform.c.orig	Tue Sep  9 14:10:18 1986
--- newform.c	Tue Sep  9 16:58:42 1986
***************
*** 558,563
  	char	*xarea,		/* Temporary pointer to character array	*/
  		UNDEF = '\377',		/* Undefined char for return */
  		*temp;		/* Array pointer			*/
  
  	xarea = area;
  	if (kludge && (fp == stdin)) {

--- 559,566 -----
  	char	*xarea,		/* Temporary pointer to character array	*/
  		UNDEF = '\377',		/* Undefined char for return */
  		*temp;		/* Array pointer			*/
+ 	int	cnt = NCOLS;	/* Count chars read in 			*/
+ 	int	errflg = 0;	/* Line too long aleady been said	*/
  
  	xarea = area;
  	if (kludge && (fp == stdin)) {
***************
*** 567,573
  		return(xarea);
  		}
  	else {
! 		while ((*area++ = c = getc(fp)) != '\n' && c != EOF) ;
  		if (c == EOF) {
  			if (--area == xarea)return(NULL);
  			else {

--- 570,584 -----
  		return(xarea);
  		}
  	else {
! 		while ((*area++ = c = getc(fp)) != '\n' && c != EOF)
! 			if (cnt-- <= 0) {
! 				area--;
! 				if (!errflg) {
! 					fprintf(stderr,
! 						"newform: input line too long, truncated\n");
! 					errflg++;
! 				}
! 			}
  		if (c == EOF) {
  			if (--area == xarea)return(NULL);
  			else {
***************
*** 576,582
  				}
  			}
  		}
! return(&UNDEF);	/* Stops 'lint's complaint about return(e) VS return. */
  }
  /* _________________________________________________________________ */
  

--- 587,593 -----
  				}
  			}
  		}
! 	return(xarea);
  }
  /* _________________________________________________________________ */
  
-- 
	-Mike Wescott
	 ncrcae!wescott



More information about the Net.bugs.usg mailing list