*BSD News Article 9553


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA5973 ; Sat, 02 Jan 93 10:07:55 EST
Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!spool.mu.edu!umn.edu!umeecs!quip.eecs.umich.edu!dmuntz
From: dmuntz@quip.eecs.umich.edu (Dan Muntz)
Subject: [386BSD] csh globbing bug
Message-ID: <1993Jan5.051039.29362@zip.eecs.umich.edu>
Sender: news@zip.eecs.umich.edu (Mr. News)
Organization: University of Michigan EECS Dept., Ann Arbor, MI
Date: Tue, 5 Jan 1993 05:10:39 GMT
Lines: 74

I don't know if this one has been mentioned or fixed.
Any wildcard which fails to match anything causes a "No match" for the
entire argument list.  The included patch takes care to mimic the 
standard globbing of csh (if it has been changed for POSIX or somesuch
someone please let me know :)

To see the bug:

% ls
foo.a   bar.b  
% ls *.b *.c
ls: No match.

  -Dan
   dmuntz@eecs.umich.edu

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

*** glob.c.ORIG	Sun Jan  3 19:45:16 1993
--- glob.c	Sun Jan  3 23:46:47 1993
***************
*** 354,360 ****
  libglob(vl)
      Char  **vl;
  {
!     int     gflgs = GLOB_QUOTE | GLOB_NOCHECK;
      glob_t  globv;
      char   *ptr;
  
--- 354,360 ----
  libglob(vl)
      Char  **vl;
  {
!     int     gflgs = GLOB_QUOTE | GLOB_NOCHECK, badmagic = 0, goodmagic = 0;
      glob_t  globv;
      char   *ptr;
  
***************
*** 377,388 ****
  	}
  	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);
--- 377,397 ----
  	}
  	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);