From iedowse@maths.tcd.ie Wed May 26 15:24:05 1999
Return-Path: <iedowse@maths.tcd.ie>
Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11])
	by hub.freebsd.org (Postfix) with SMTP id 8691714DF7
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 May 1999 15:23:52 -0700 (PDT)
	(envelope-from iedowse@maths.tcd.ie)
Received: from gosset.maths.tcd.ie by salmon.maths.tcd.ie with SMTP
          id <aa11066@salmon.maths.tcd.ie>; 26 May 99 23:23:52 +0100 (BST)
Message-Id: <199905262323.aa75046@gosset.maths.tcd.ie>
Date: Wed, 26 May 1999 23:23:51 +0100 (BST)
From: iedowse@maths.tcd.ie
Sender: iedowse@maths.tcd.ie
Reply-To: iedowse@maths.tcd.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: Sed(1) fails with MALLOC_OPTIONS set to 'V'
X-Send-Pr-Version: 3.2

>Number:         11900
>Category:       bin
>Synopsis:       Sed(1) fails with MALLOC_OPTIONS set to 'V'
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mikeh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 26 15:30:01 PDT 1999
>Closed-Date:    Wed Nov 28 21:24:12 PST 2001
>Last-Modified:  Wed Nov 28 21:25:50 PST 2001
>Originator:     Ian Dowse
>Release:        FreeBSD 3.1-STABLE i386
>Organization:
	School of Mathematics
	Trinity College, Dublin
>Environment:
	All versions of FreeBSD

>Description:

	Just a trivial buglet; the synopsis says it all.

	Sed's compile() function can try to malloc zero bytes, and its
	xmalloc() wrapper treats a NULL malloc() return as a fatal error.

	Presumably other similar problems exist elsewhere in the tree. I
	just tried a 'setenv MALLOC_OPTIONS AJVX; make world' and almost
	immediately ld(1) gave a similar error (on a 2-week old -current).
	While not at all critical, it would be nice for standard utilities
	to work with any malloc options.
	
>How-To-Repeat:

	% setenv MALLOC_OPTIONS V
	% sed
	sed: malloc: Undefined error: 0
>Fix:

Apply this patch to src/usr.bin/sed/compile.c

--- compile.c.orig	Wed May 26 21:19:18 1999
+++ compile.c	Wed May 26 21:23:43 1999
@@ -138,7 +138,10 @@
 	*compile_stream(&prog) = NULL;
 	fixuplabel(prog, NULL);
 	uselabel();
-	appends = xmalloc(sizeof(struct s_appends) * appendnum);
+	if (appendnum > 0)
+		appends = xmalloc(sizeof(struct s_appends) * appendnum);
+	else
+		appends = NULL;
 	match = xmalloc((maxnsub + 1) * sizeof(regmatch_t));
 }
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mikeh 
Responsible-Changed-By: mikeh 
Responsible-Changed-When: Sat Jun 23 19:50:19 PDT 2001 
Responsible-Changed-Why:  
I'll take a look at this. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=11900 
State-Changed-From-To: open->closed 
State-Changed-By: mikeh 
State-Changed-When: Wed Nov 28 21:24:12 PST 2001 
State-Changed-Why:  
Committed, thanks! 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=11900 
>Unformatted:
