[comp.bugs.sys5] bug in new version of awk

stevens@hsi.UUCP (11/11/87)

Index:	awk/lib.c

Description:
	The new version of awk (available from the AT&T Toolchest -
	supposedly its also shipped with System 5.3.1) dumps core.
	If you don't pass enough arguments to awk's printf(), an error
	message is printed, with a copy of your format string that
	was in error.  When this format string reaches awk's error()
	function it is passed to fprintf().  However, since there are
	probably per-cent signs in your format argument to awk's printf,
	when awk's error() calls fprintf, it'll reference random memory
	locations through the stack trying to find the non-existent arguments.

Repeat-By:
	nawk '{printf("%s%s", "hi")}'       (then enter a return)

		This causes a core dump on a VAX running 4.3 BSD.
		Since the problem is random memory references through
		the stack, the symptoms will differ on other systems.
Fix:

*** /tmp/,RCSt1014068	Wed Nov 11 14:34:27 1987
--- /tmp/,RCSt2014068	Wed Nov 11 14:34:28 1987
***************
*** 442,452 ****
  	int f;
  	char *s;
  {
  	extern Node *curnode;
  	extern uchar *cmdname;
  
  	fprintf(stderr, "%s: ", cmdname);
! 	fprintf(stderr, s);
  	fprintf(stderr, "\n");
  	if (NR && *NR > 0) {
  		fprintf(stderr, " input record number %g", *FNR);
--- 442,457 ----
  	int f;
  	char *s;
  {
+ 	register int c;
  	extern Node *curnode;
  	extern uchar *cmdname;
  
  	fprintf(stderr, "%s: ", cmdname);
! #ifdef	notdef
! 	fprintf(stderr, s);	/* wont work if s contains any percents */
! #endif
! 	while (c = *s++)
! 		putc(c, stderr);
  	fprintf(stderr, "\n");
  	if (NR && *NR > 0) {
  		fprintf(stderr, " input record number %g", *FNR);

guy@gorodish.Sun.COM (Guy Harris) (12/11/87)

> Repeat-By:
> 	nawk '{printf("%s%s", "hi")}'       (then enter a return)
> 
> 		This causes a core dump on a VAX running 4.3 BSD.

Fixed in the S5R3.1 version.  The code there is different (I assume that the
routine you fixed here is "error" in "lib.c"); "error" takes a potload of
arguments and passes them, along with "s", to "fprintf".
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com