*BSD News Article 23152


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!haven.umd.edu!news.umbc.edu!eff!news.kei.com!yeshua.marcam.com!zip.eecs.umich.edu!quip.eecs.umich.edu!dmuntz
From: dmuntz@quip.eecs.umich.edu (Dan Muntz)
Newsgroups: comp.os.386bsd.bugs
Subject: csh glob bug
Date: 2 Nov 1993 05:06:27 GMT
Organization: University of Michigan EECS Dept., Ann Arbor, MI
Lines: 72
Message-ID: <2b4psj$83o@zip.eecs.umich.edu>
NNTP-Posting-Host: quip.eecs.umich.edu

This applies to NetBSD 0.9 and probably FreeBSD.
Any wildcard which matches nothing causes a "No match" for the entire argument
list.  The included patch takes care to mimic the standard globbing of csh.

To see the bug:

% touch aa bb
% ls
aa	bb
% ls *b *ccc
ls: No match.

  -Dan
   dmuntz@eecs.umich.edu

And the patch (to /usr/src/bin/csh/glob.c):

*** glob.c.ORIG	Tue Nov  2 00:00:41 1993
--- glob.c	Tue Nov  2 00:01:04 1993
***************
*** 355,361 ****
  libglob(vl)
      Char  **vl;
  {
!     int     gflgs = GLOB_QUOTE | GLOB_NOCHECK;
      glob_t  globv;
      char   *ptr;
  
--- 355,361 ----
  libglob(vl)
      Char  **vl;
  {
!     int     gflgs = GLOB_QUOTE | GLOB_NOCHECK, badmagic = 0, goodmagic = 0;
      glob_t  globv;
      char   *ptr;
  
***************
*** 378,389 ****
  	}
  	if (!nonomatch && (globv.gl_matchc == 0) &&
  	    (globv.gl_flags & GLOB_MAGCHAR)) {
! 	    globfree(&globv);
! 	    return (NULL);
! 	}
  	gflgs |= GLOB_APPEND;
      }
      while (*++vl);
      vl = blk2short(globv.gl_pathv);
      globfree(&globv);
      return (vl);
--- 378,398 ----
  	}
  	if (!nonomatch && (globv.gl_matchc == 0) &&
  	    (globv.gl_flags & GLOB_MAGCHAR)) {
! 	    badmagic = 1;
! 	    globv.gl_pathc--;
! 	    free(globv.gl_pathv[globv.gl_pathc]);
! 	    globv.gl_pathv[globv.gl_pathc] = (char *)0;
! 	} else
! 	    if (!nonomatch && (globv.gl_matchc > 0) && 
! 		(globv.gl_flags & GLOB_MAGCHAR))
! 		goodmagic = 1;
  	gflgs |= GLOB_APPEND;
      }
      while (*++vl);
+     if (badmagic && !goodmagic) {
+ 	globfree(&globv);
+ 	return (NULL);
+     }
      vl = blk2short(globv.gl_pathv);
      globfree(&globv);
      return (vl);