From fenner@stash.attlabs.att.com  Sat Mar 17 17:42:10 2001
Return-Path: <fenner@stash.attlabs.att.com>
Received: from stash.attlabs.att.com (mpfg.attlabs.net [12.106.35.2])
	by hub.freebsd.org (Postfix) with ESMTP id 830CE37B718
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Mar 2001 17:42:10 -0800 (PST)
	(envelope-from fenner@stash.attlabs.att.com)
Received: (from fenner@localhost)
	by stash.attlabs.att.com (8.11.2/8.11.2) id f2I1cel91374;
	Sat, 17 Mar 2001 17:38:40 -0800 (PST)
	(envelope-from fenner)
Message-Id: <200103180138.f2I1cel91374@stash.attlabs.att.com>
Date: Sat, 17 Mar 2001 17:38:40 -0800 (PST)
From: Bill Fenner <fenner@research.att.com>
Reply-To: fenner@research.att.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: cgetset(3) doesn't get cleared when switching databases
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         25886
>Category:       kern
>Synopsis:       [libc] cgetset(3) doesn't get cleared when switching databases
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 17 17:50:01 PST 2001
>Closed-Date:    
>Last-Modified:  Tue Apr 21 00:02:13 UTC 2009
>Originator:     Bill Fenner
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
AT&T Labs - Research
>Environment:
System: FreeBSD stash.attlabs.att.com 5.0-CURRENT FreeBSD 5.0-CURRENT #2: Tue Feb 27 18:26:16 PST 2001 root@stash.attlabs.att.com:/usr/obj/usr/src/sys/GENERIC i386

The bug is also present in 4.2-RELEASE and 4.3-BETA.

>Description:

The getcap(3) library provides the ability, using cgetset(), to
prepend an entry to a capabilities database.  This is used, e.g.,
by libtermcap when the $TERMCAP environment variable is set.

However, if an application using libtermcap also uses getcap(3)
itself, the value prepended by libtermcap is also prepended to
the application's database.

This is noted in the getcap(3) BUGS section, so I suppose this is
vaugely an lpc bug.

>How-To-Repeat:

% eval `tset -s`
% lpc
lpc> stat all

Notice the extra printer named after your terminal type.
% echo "$TERMCAP"

aha, that's where it came from.

>Fix:

	
Workaround: call cgetset(NULL) right before the first cgetfirst()
in any getcap(3) consumer (e.g. usr.sbin/lpr/common_source/printcap.c),
particularly those that link with -ltermcap (but who knows what other
library function might use cgetset(), so better safe than sorry).

Fix: Change the getcap(3) API?  Make cgetfirst() notice that it's being
called with a different db_array without a cgetset() call in between
and call cgetset(NULL)?  (eeew)  Make cgetclose() call cgetset(NULL)
if gottoprec == 1?  (subtle API change but less eeew)

>Release-Note:
>Audit-Trail:
>Unformatted:
