Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 May 2000 22:20:49 -0700 (PDT)
From:      douzzer@mega.nu
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/18704: GLOB_ERR not handled correctly by glob()
Message-ID:  <20000521052049.BD73A37B580@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         18704
>Category:       kern
>Synopsis:       GLOB_ERR not handled correctly by glob()
>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 May 20 22:30:01 PDT 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000521052049.BD73A37B580>