From dan@dan.emsphone.com  Fri Jul  9 02:38:41 2004
Return-Path: <dan@dan.emsphone.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id ADE4F16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Jul 2004 02:38:41 +0000 (GMT)
Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6906B43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri,  9 Jul 2004 02:38:41 +0000 (GMT)
	(envelope-from dan@dan.emsphone.com)
Received: (from dan@localhost)
	by dan.emsphone.com (8.12.10/8.12.10) id i692ce5R019205;
	Thu, 8 Jul 2004 21:38:40 -0500 (CDT)
	(envelope-from dan)
Message-Id: <200407090238.i692ce5R019205@dan.emsphone.com>
Date: Thu, 8 Jul 2004 21:38:40 -0500 (CDT)
From: Dan Nelson <dan@dan.emsphone.com>
Reply-To: Dan Nelson <dan@dan.emsphone.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] gcore hangs on current
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         68839
>Category:       bin
>Synopsis:       [PATCH] gcore hangs on current
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 09 02:40:22 GMT 2004
>Closed-Date:    Tue Jul 13 14:04:20 GMT 2004
>Last-Modified:  Tue Jul 13 14:04:20 GMT 2004
>Originator:     Dan Nelson
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
The Allant Group
>Environment:
System: FreeBSD dan.emsphone.com 5.2-CURRENT FreeBSD 5.2-CURRENT #341: Wed Jun 23 23:03:45 CDT 2004 zsh@dan.emsphone.com:/usr/src/sys/i386/compile/DANSMP i386

	
>Description:
	

The 2003/09/29 commit to procfs_map.c added a column to /proc/*/map. 
This breaks gcore, which ends up in an infinite loop trying to parse
the first line of the mapfile over and over and over with the wrong
number of fields.

>How-To-Repeat:

$ gcore $$
<wait forever>
$
	
>Fix:

Parse the new field, and add a sanity check that we scanned a nonzero
number of characters so when someone changes the format of /proc/*/map
again gcore will catch it.  gcore should probably be rewritten to not
use /procfs.

Index: elfcore.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/gcore/elfcore.c,v
retrieving revision 1.16
diff -u -r1.16 elfcore.c
--- elfcore.c	15 Feb 2004 22:48:25 -0000	1.16
+++ elfcore.c	9 Jul 2004 02:16:54 -0000
@@ -504,10 +504,10 @@
 
 		len = 0;
 		n = sscanf(mapbuf + pos, "%x %x %*d %*d %*x %3[-rwx]"
-		    " %*d %*d %*x %*s %*s %16s%*[\n]%n",
+		    " %*d %*d %*x %*s %*s %16s %*s%*[\n]%n",
 		    &start, &end, prot, type, &len);
-		if (n != 4)
-			errx(1, "ill-formed line in %s", mapname);
+		if (n != 4 || len == 0)
+			errx(1, "ill-formed line in %s starting at character %d", mapname, pos + 1);
 		pos += len;
 
 		/* Ignore segments of the wrong kind, and unwritable ones */

	


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: rwatson 
State-Changed-When: Mon Jul 12 20:19:55 GMT 2004 
State-Changed-Why:  
I've committed the patch as-is, and wanted to confirm that in the 
committed state all is well. 



Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Mon Jul 12 20:19:55 GMT 2004 
Responsible-Changed-Why:  
Take ownership of this PR since I introduced the procfs field in 
question. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=68839 
State-Changed-From-To: feedback->closed 
State-Changed-By: rwatson 
State-Changed-When: Tue Jul 13 14:04:08 GMT 2004 
State-Changed-Why:  
Thanks for the bugfix! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=68839 
>Unformatted:
