From ubergeek@terrafirma.cstone.net Wed May 26 09:25:39 1999
Return-Path: <ubergeek@terrafirma.cstone.net>
Received: from terrafirma.cstone.net (terrafirma.cstone.net [205.197.102.33])
	by hub.freebsd.org (Postfix) with ESMTP id B171E15694
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 26 May 1999 09:25:34 -0700 (PDT)
	(envelope-from ubergeek@terrafirma.cstone.net)
Received: (from ubergeek@localhost)
	by terrafirma.cstone.net (8.9.3/8.9.2) id MAA03104;
	Wed, 26 May 1999 12:26:22 -0400 (EDT)
	(envelope-from ubergeek)
Message-Id: <199905261626.MAA03104@terrafirma.cstone.net>
Date: Wed, 26 May 1999 12:26:22 -0400 (EDT)
From: adrian@ubergeeks.com
Sender: ubergeek@terrafirma.cstone.net
Reply-To: adrian@ubergeeks.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: argument checking on cap_mkdb
X-Send-Pr-Version: 3.2

>Number:         11896
>Category:       bin
>Synopsis:       cap_mkdb dumps core  when non-files passed as arguments
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 26 09:30:01 PDT 1999
>Closed-Date:    Fri Jun 15 14:51:22 MDT 2001
>Last-Modified:  Fri Jun 15 14:51:46 MDT 2001
>Originator:     Adrian Filipi-Martin
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
Ubergeeks Consulting
>Environment:

	3.2-RLEASE as built locally and installed on about 5/17.

>Description:

	If passed a non-file, e.g. a directory, as an argument, cap_mkdb will
	segfault and dump core.

>How-To-Repeat:

	cap_mkdb /etc

>Fix:
	
	Apply this patch.  Note that I consider a FIFO ok, because sometimes
	I use the <(command|filter) idiom to feed processed data to commands 
	as file arguments.


--- cap_mkdb.c.orig	Sun Dec  6 17:58:12 1998
+++ cap_mkdb.c	Wed May 26 12:04:20 1999
@@ -75,6 +75,7 @@
 	char *argv[];
 {
 	int c;
+	const char *const progname = strrchr(argv[0], '/') + 1;
 
 	capname = NULL;
 	while ((c = getopt(argc, argv, "f:v")) != -1) {
@@ -95,6 +96,18 @@
 
 	if (*argv == NULL)
 		usage();
+	else {
+		char **p = argv;
+		do {
+			struct stat sb;
+			if (stat(*p, &sb) == -1)
+				err(1, (char *)NULL);
+			if (sb.st_mode & (S_IFREG|S_IFIFO))
+				continue;
+			fprintf(stderr, "%s: %s, not a regular file", progname, *p);
+			exit(1);
+		} while (*++p);
+	}
 
 	/*
 	 * The database file is the first argument if no name is specified.

>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <charon@labs.gr>
To: freebsd-gnats-submit@FreeBSD.org, adrian@ubergeeks.com
Cc:  
Subject: Re: bin/11896: cap_mkdb dumps core  when non-files passed as arguments
Date: Thu, 14 Jun 2001 06:56:08 +0300

 I tested this on 4-STABLE and it seems to work correctly:
 The source essentially the same in RELENG_3 (where this was
 reported) and RELENG_4, apart from err() and errx() usage,
 or wanr() and warnx().
 
 Running the proposed command to test the problem:
 
 	# cap_mkdb /etc
 	cap_mkdb: file argument: Undefined error: 0
 
 It seems that the problem was not in cap_mkdb itself,
 but most likely in the dbopen() call.
 This doesnt seem to be a problem anymore.
 
 This PR can be closed.
 
 -giorgos
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Fri Jun 15 14:51:22 MDT 2001 
State-Changed-Why:  
This appears to be fixed.  I've also confirmed that it works as expected in 
current this date. 

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