🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs
Article #192

Bug in awk substring routine dumps core

#192
From: Ken Reek
Date: Thu, 29 Mar 1984 21:29
61 lines
2239 bytes
There is a bug in the substring routine in awk that can cause it to fail with
a memory fault.  Briefly, the problem stems from keeping a pointer to a string
and using the pointer after the memory containing it has been free'd.  Using
the pointer later may corrupt malloc's storage arena, which eventually causes
the failure.  The awk program I had that failed is too long to include here;
if anyone is interested, drop me a note.

To fix the problem, change "run.c" as shown below.  The line numbers may be
off a little, as I've changed many of the declarations to use registers.


***255,262 (originally)
obj substr(a, nnn) node **a;
{
	char *s, temp;
	obj x;
	int k, m, n;

	x = execute(a[0]);
	s = getsval(x.optr);

---255,262 (corrected)
obj substr(a, nnn) node **a;
{
	char *s, temp;
!	obj x, y;
	int k, m, n;

!	y = execute(a[0]);
!	s = getsval(y.optr);


***263,265 (originally)
	k = strlen(s) + 1;
!	tempfree(x);
	x = execute(a[1]);

---263,264 (corrected)
	k = strlen(s) + 1;
	x = execute(a[1]);


***288,289 (originally)
	s[n+m-1] = temp;
	return(x);

---287,289 (corrected)
	s[n+m-1] = temp;
!	tempfree(y);
	return(x);


I've also incorporated changes for a version that uses doubles instead of
floats (called dawk) and a version that uses long integers instead of floats
(called lawk).  The former is useful when greater precisions than offered by
floats is needed; the latter was most useful on our PDP-11/45 which lacked
floating point hardware -- the performance improvement averaged better than
an order of magnitude.  If you're interested, drop me a note.

	Ken Reek, Rochester Institute of Technology
	seismo!rochester!ritcv!kar
Technical Details
Message-ID: <975@ritcv.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!floyd!harpo!seismo!rochester!ritcv!kar

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site ritcv.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!floyd!harpo!seismo!rochester!ritcv!kar
From: kar@ritcv.UUCP (Ken Reek)
Newsgroups: net.bugs
Subject: Bug in awk substring routine dumps core
Message-ID: <975@ritcv.UUCP>
Date: Thu, 29-Mar-84 16:29:13 EST
Article-I.D.: ritcv.975
Posted: Thu Mar 29 16:29:13 1984
Date-Received: Sat, 31-Mar-84 07:04:17 EST
Organization: Rochester Institute of Technology, Rochester, NY
Lines: 61