From nobody@FreeBSD.ORG  Sat May 20 22:20:49 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id BD73A37B580; Sat, 20 May 2000 22:20:49 -0700 (PDT)
Message-Id: <20000521052049.BD73A37B580@hub.freebsd.org>
Date: Sat, 20 May 2000 22:20:49 -0700 (PDT)
From: douzzer@mega.nu
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: GLOB_ERR not handled correctly by glob()
X-Send-Pr-Version: www-1.0

>Number:         18704
>Category:       kern
>Synopsis:       GLOB_ERR not handled correctly by glob()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 20 22:30:01 PDT 2000
>Closed-Date:    
>Last-Modified:  Sat Sep 11 23:01:16 GMT 2004
>Originator:     Daniel Pouzzner
>Release:        4.0-RELEASE
>Organization:
>Environment:
FreeBSD mega 4.0-RELEASE FreeBSD 4.0-RELEASE #10: Mon Apr 24 19:27:08 EDT 2000     douzzer@mega:/usr/src/sys/compile/MEGA  i386

>Description:
glob() (and internal funcs) never checks GLOB_ERR unless an error
handler pointer is passed.  Even with a handler, GLOB_ERR is only
partially implemented, and conditions which should activate the
semantic do not.  Finally, conditions which should not activate
the semantic do, rendering GLOB_ERR far less useful than it should
be (a TODO identifying this problem was in the source tree, and
I implemented the fix).

>How-To-Repeat:
Do that math :-P
glob("/secretdir/*",GLOB_ERR,0,&globbuf) where /secretdir is not
accessible - should result in negative return value, but does not.

>Fix:
The following context diff was pasted from emacs - tabs are intact.

*** /usr/src/lib/libc/gen/glob.c	Fri Feb 20 02:54:56 1998
--- /tmp/glob.c	Sun May 21 01:19:24 2000
***************
*** 532,540 ****
  	for (anymeta = 0;;) {
  		if (*pattern == EOS) {		/* End of pattern? */
  			*pathend = EOS;
! 			if (g_lstat(pathbuf, &sb, pglob))
! 				return(0);
! 
  			if (((pglob->gl_flags & GLOB_MARK) &&
  			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
  			    || (S_ISLNK(sb.st_mode) &&
--- 532,543 ----
  	for (anymeta = 0;;) {
  		if (*pattern == EOS) {		/* End of pattern? */
  			*pathend = EOS;
! 			if (g_lstat(pathbuf, &sb, pglob)) {
! 			  if (pglob->gl_flags & GLOB_ERR)
! 			  	return GLOB_ABEND;
! 			  else
! 			  	return(0);
! 			}
  			if (((pglob->gl_flags & GLOB_MARK) &&
  			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
  			    || (S_ISLNK(sb.st_mode) &&
***************
*** 589,599 ****
  	errno = 0;
  
  	if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
! 		/* TODO: don't call for ENOENT or ENOTDIR? */
  		if (pglob->gl_errfunc) {
  			g_Ctoc(pathbuf, buf);
! 			if (pglob->gl_errfunc(buf, errno) ||
! 			    pglob->gl_flags & GLOB_ERR)
  				return (GLOB_ABEND);
  		}
  		return(0);
--- 592,602 ----
  	errno = 0;
  
  	if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
! 		if ((pglob->gl_flags & GLOB_ERR) && (errno != ENOENT) && (errno != ENOTDIR))
! 			return GLOB_ABEND;
  		if (pglob->gl_errfunc) {
  			g_Ctoc(pathbuf, buf);
! 			if (pglob->gl_errfunc(buf, errno))
  				return (GLOB_ABEND);
  		}
  		return(0);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: mike 
State-Changed-When: Sat Jul 21 19:40:12 PDT 2001 
State-Changed-Why:  

Does this problem still occur in newer versions of FreeBSD, 
such as 4.3-RELEASE? 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18704 

From: Mike Barcroft <mike@FreeBSD.org>
To: Daniel Pouzzner <douzzer@mega.nu>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/18704: GLOB_ERR not handled correctly by glob()
Date: Sat, 21 Jul 2001 23:12:50 -0400

 On Sat, Jul 21, 2001 at 10:47:04PM -0400, Daniel Pouzzner wrote:
 > >Does this problem still occur in newer versions of FreeBSD,
 > >such as 4.3-RELEASE?
 > 
 > I submitted that bug report so long I don't even remember what I was
 > working on that had me using the glob routines.  I do remember
 > submitting the bug report at least.
 > 
 > Can you send me a URL where I can read my bug report for a refresher?
 
 Hmm, the URL should have been at the bottom of the message Gnats
 sent you.  Anyway, here it is:
 
 http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18704
 
 Best regards,
 Mike Barcroft

From: Mike Barcroft <mike@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/18704: GLOB_ERR not handled correctly by glob()
Date: Sat, 21 Jul 2001 23:53:42 -0400

 Adding to Audit-Trail.
 
 On Sat, Jul 21, 2001 at 11:17:42PM -0400, Daniel Pouzzner wrote:
 > I just checked the 4.3 code (Mar 28 modtime on glob.c) and no repair
 > has been implemented (notably, my suggested repair has not been
 > merged).
 > 
 >   Synopsis: GLOB_ERR not handled correctly by glob()
 >   
 >   State-Changed-From-To: open->feedback
 >   State-Changed-By: mike
 >   State-Changed-When: Sat Jul 21 19:40:12 PDT 2001
 >   State-Changed-Why: 
 >   
 >   Does this problem still occur in newer versions of FreeBSD,
 >   such as 4.3-RELEASE?
 >   
 >   http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18704
State-Changed-From-To: feedback->suspended 
State-Changed-By: mike 
State-Changed-When: Sat Jul 21 20:44:26 PDT 2001 
State-Changed-Why:  

This is still a problem.  Awaiting committer. 

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