From murduth@rmstar.campus.luth.se  Sat Jan  2 19:47:12 1999
Received: from rmstar.campus.luth.se (rmstar.campus.luth.se [130.240.197.32])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA07660
          for <FreeBSD-gnats-submit@FreeBSD.org>; Sat, 2 Jan 1999 19:47:11 -0800 (PST)
          (envelope-from murduth@rmstar.campus.luth.se)
Received: (from root@localhost)
	by rmstar.campus.luth.se (8.9.1/8.9.1) id EAA41959;
	Sun, 3 Jan 1999 04:46:40 +0100 (CET)
	(envelope-from murduth)
Message-Id: <199901030346.EAA41959@rmstar.campus.luth.se>
Date: Sun, 3 Jan 1999 04:46:40 +0100 (CET)
From: murduth@ludd.luth.se
Reply-To: murduth@ludd.luth.se
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: [PATCH] awk uses junk memory
X-Send-Pr-Version: 3.2

>Number:         9281
>Category:       bin
>Synopsis:       awk asumes memory that is returned from malloc is clean.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan  2 19:50:00 PST 1999
>Closed-Date:    Tue Dec 21 06:50:56 PST 1999
>Last-Modified:  Tue Dec 21 06:52:06 PST 1999
>Originator:     Joakim Henriksson
>Release:        FreeBSD-CURRENT
>Organization:
FreeBSD
>Environment:

/usr/src/contrib/awk/awk.y version 1.1.1.1

>Description:

When repporting errors (and problably other places i havn't found/looked for)
awk puts out garbage due to non null memory from malloc.

>How-To-Repeat:

cd /etc ; ln -s malloc.conf AJ
cd ; cat > test.awk
/foo/{
{if (FNR==2) foo = $0}
^D
awk -f test.awk

>Fix:

Apply following patch in /usr/src.
	
*** contrib/awk/awk.y.orig      Sun Jan  3 03:54:24 1999
--- contrib/awk/awk.y   Sun Jan  3 04:29:59 1999
***************
*** 1091,1096 ****
--- 1091,1097 ----
                                }
                        len = lexptr - scan;
                        emalloc(buf, char *, len+1, "get_src_buf");
+                       bzero(buf, len + 1);
                        memcpy(buf, scan, len);
                        thisline = buf;
                        lexptr = buf + len;
***************
*** 1130,1136 ****
                newfile = TRUE;
                if (buf != NULL)
                        free(buf);
!               emalloc(buf, char *, len + SLOP, "get_src_buf");
                lexptr_begin = buf + SLOP;
                samefile = TRUE;
                sourceline = 1;
--- 1131,1138 ----
                newfile = TRUE;
                if (buf != NULL)
                        free(buf);
!               emalloc(buf, char *, len + SLOP + 1, "get_src_buf");
!               bzero(buf, len + SLOP + 1);
                lexptr_begin = buf + SLOP;
                samefile = TRUE;
                sourceline = 1;

>Release-Note:
>Audit-Trail:

From: hoek@freebsd.org
To: freebsd-gnats-submit@freebsd.org, murduth@ludd.luth.se
Cc:  
Subject: Re:bin/9281
Date: Mon, 2 Aug 1999 21:16:30 -0400 (EDT)

 >
 >When repporting errors (and problably other places i havn't found/looked for)
 >awk puts out garbage due to non null memory from malloc.
 
 Probable duplicate of gnu/7821 and gnu/12935.
 
 The patch included in this PR is either harmless or correct (probably
 the latter).  For the moment I've declined to apply it since I'd prefer
 to see gawk upgraded in the contrib section and applying the patch would
 create more conflicts when the upgrade occurs.  However, if nobody
 upgrades gawk within a reasonable time period, the patch should be applied
 to see what it fixes.
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Tue Dec 21 06:50:56 PST 1999 
State-Changed-Why:  
Our gawk was upgraded to 3.0.4 in CURRENT a while ago and merged in 
time for 3.4-RELEASE. 
>Unformatted:
