From nobody@FreeBSD.org  Mon Mar 15 20:51:13 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 2A00016A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Mar 2004 20:51:13 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2350243D2F
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Mar 2004 20:51:13 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.10/8.12.10) with ESMTP id i2G4pC72096960
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 15 Mar 2004 20:51:12 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.10/8.12.10/Submit) id i2G4pCtA096959;
	Mon, 15 Mar 2004 20:51:12 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200403160451.i2G4pCtA096959@www.freebsd.org>
Date: Mon, 15 Mar 2004 20:51:12 -0800 (PST)
From: Rodney Ruddock <rodney@interopsystems.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pax cacheing bug
X-Send-Pr-Version: www-2.3

>Number:         64321
>Category:       bin
>Synopsis:       pax cacheing bug
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    cperciva
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Mar 15 21:00:31 PST 2004
>Closed-Date:    Fri Mar 19 00:27:29 PST 2004
>Last-Modified:  Fri Mar 19 00:27:29 PST 2004
>Originator:     Rodney Ruddock
>Release:        none
>Organization:
Interop Systems
>Environment:
none
>Description:
      In the file bin/pax/cache.c for the functions name_uid() and name_gid() the cacheing is not working. I already submitted the same fix to OpenBSD and it's been committed. I expect the same bug has existed since 4.4 since all of the BSD's seem to have it.
Anyway, when a uid/gid is not found in the hashed table then a chunk of memory is allocated to "ptr" and then the info is looked up and stored in "ptr". This info in "ptr" is never added to the table. The memory now leaks away and no information has been cached. So the cache doesn't work.
>How-To-Repeat:
      Read the code.
Otherwise you can run a trace on function calls and see getpwuid() and getgrgid() get called repeatedly for the same id's when an archive is being extracted.
>Fix:
      This is the diff as applied to OpenBSD for bin/pax/cache.c:
@@ -204,7 +204,7 @@
 		++pwopn;
 	}
 	if (ptr == NULL)
-		ptr = (UIDC *)malloc(sizeof(UIDC));
+		ptr = uidtb[uid % UID_SZ] = malloc(sizeof(UIDC));
 
 	if ((pw = getpwuid(uid)) == NULL) {
 		/*
@@ -270,7 +270,7 @@
 		++gropn;
 	}
 	if (ptr == NULL)
-		ptr = (GIDC *)malloc(sizeof(GIDC));
+		ptr = gidtb[gid % GID_SZ] = malloc(sizeof(GIDC));
 
 	if ((gr = getgrgid(gid)) == NULL) {
 		/*
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: cperciva 
State-Changed-When: Tue Mar 16 00:33:58 PST 2004 
State-Changed-Why:  
Fixed in -current, will MFC in 3 days. 


Responsible-Changed-From-To: freebsd-bugs->cperciva 
Responsible-Changed-By: cperciva 
Responsible-Changed-When: Tue Mar 16 00:33:58 PST 2004 
Responsible-Changed-Why:  
Fixed in -current, will MFC in 3 days. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=64321 
State-Changed-From-To: patched->closed 
State-Changed-By: cperciva 
State-Changed-When: Fri Mar 19 00:27:13 PST 2004 
State-Changed-Why:  
MFC done. 

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