Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glob() produces spurious results with brackets in braces #8759

Closed
p5pRT opened this issue Feb 1, 2007 · 7 comments
Closed

glob() produces spurious results with brackets in braces #8759

p5pRT opened this issue Feb 1, 2007 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 1, 2007

Migrated from rt.perl.org#41421 (status was 'resolved')

Searchable as RT41421$

@p5pRT
Copy link
Author

p5pRT commented Feb 1, 2007

From @pjscott

glob() is listing files that I don't think it should in this example
(and it doesn't match the tcsh globbing behavior on either Solaris or Fedora)​:

$ ls -1
a_dej
a_ghj
a_qej

$ perl -le 'print for glob "a*{d[ef],g[hi]}j"'
a_dej
a_qej
a_ghj

$ ls -1 a*{d[ef],g[hi]}j
a_dej
a_ghj
$

This is with at least 5.8.8 and blead.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:
  Platform​:
  osname=linux, osvers=2.6.16-1.2133_fc5, archname=i686-linux
  uname='linux tweety 2.6.16-1.2133_fc5 #1 tue jun 6 00​:52​:14 edt
2006 i686 athlon i386 gnulinux '
  config_args='-des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-strict-aliasing -pipe
-Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
  optimize='-O2',
  cppflags='-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include -I/usr/include/gdbm'
  ccversion='', gccversion='4.1.1 20060525 (Red Hat 4.1.1-1)',
gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
  libc=/lib/libc-2.4.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.4'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Compile-time options​: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO
  Built under linux
  Compiled at Oct 11 2006 10​:08​:13
  @​INC​:
  /usr/local/lib/perl5/5.8.8/i686-linux
  /usr/local/lib/perl5/5.8.8
  /usr/local/lib/perl5/site_perl/5.8.8/i686-linux
  /usr/local/lib/perl5/site_perl/5.8.8
  /usr/local/lib/perl5/site_perl
  .
--
Peter Scott
Pacific Systems Design Technologies
http​://www.perldebugged.com/
http​://www.perlmedic.com/

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2007

From @eserte

Peter Scott (via RT) <perlbug-followup@​perl.org> writes​:

# New Ticket Created by Peter Scott
# Please include the string​: [perl #41421]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=41421 >

glob() is listing files that I don't think it should in this example
(and it doesn't match the tcsh globbing behavior on either Solaris or Fedora)​:

$ ls -1
a_dej
a_ghj
a_qej

$ perl -le 'print for glob "a*{d[ef],g[hi]}j"'
a_dej
a_qej
a_ghj

$ ls -1 a*{d[ef],g[hi]}j
a_dej
a_ghj
$

This is with at least 5.8.8 and blead.

I compared the bsd_glob.c with FreeBSD 6.1's lib/libc/gen/glob.c and
of the ~150 differences one looked very promising and indeed seems to
fix the problem. Attached is the patch including a new (and hopefully
portable) test case.

Regards,
  Slaven

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2007

From @eserte

file-glob.patch
# 
# 
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####

#### Patch data follows ####
diff -up 'bleedperl/ext/File/Glob/bsd_glob.c' 'bleedperl2/ext/File/Glob/bsd_glob.c'
Index: ./ext/File/Glob/bsd_glob.c
Prereq: 	8.3 
--- ./ext/File/Glob/bsd_glob.c	Wed Aug 16 19:45:11 2006
+++ ./ext/File/Glob/bsd_glob.c	Fri Feb  2 22:05:52 2007
@@ -431,7 +431,7 @@ globexp2(const Char *ptr, const Char *pa
 {
 	int     i;
 	Char   *lm, *ls;
-	const Char *pe, *pm, *pl;
+	const Char *pe, *pm, *pm1, *pl;
 	Char    patbuf[MAXPATHLEN];
 
 	/* copy part up to the brace */
@@ -471,14 +471,14 @@ globexp2(const Char *ptr, const Char *pa
 		switch (*pm) {
 		case BG_LBRACKET:
 			/* Ignore everything between [] */
-			for (pl = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
+			for (pm1 = pm++; *pm != BG_RBRACKET && *pm != BG_EOS; pm++)
 				;
 			if (*pm == BG_EOS) {
 				/*
 				 * We could not find a matching BG_RBRACKET.
 				 * Ignore and just look for BG_RBRACE
 				 */
-				pm = pl;
+				pm = pm1;
 			}
 			break;
 
diff -up 'bleedperl/ext/File/Glob/t/basic.t' 'bleedperl2/ext/File/Glob/t/basic.t'
Index: ./ext/File/Glob/t/basic.t
--- ./ext/File/Glob/t/basic.t	Tue Jun 13 21:29:07 2006
+++ ./ext/File/Glob/t/basic.t	Fri Feb  2 22:18:42 2007
@@ -13,7 +13,7 @@ BEGIN {
         print "1..0\n";
         exit 0;
     }
-    print "1..12\n";
+    print "1..13\n";
 }
 END {
     print "not ok 1\n" unless $loaded;
@@ -187,3 +187,26 @@ rmdir "pteerslo";
 # this can panic if PL_glob_index gets passed as flags to bsd_glob
 <*>; <*>;
 print "ok 12\n";
+
+{
+    use File::Temp qw(tempdir);
+    use File::Spec qw();
+
+    my($dir) = tempdir(CLEANUP => 1)
+	or die "Could not create temporary directory";
+    for my $file (qw(a_dej a_ghj a_qej)) {
+	open my $fh, ">", File::Spec->catfile($dir, $file)
+	    or die "Could not create file $dir/$file: $!";
+	close $fh;
+    }
+    my $cwd = Cwd::cwd();
+    chdir $dir
+	or die "Could not chdir to $dir: $!";
+    my(@glob_files) = glob("a*{d[e]}j");
+    if (!(@glob_files == 1 && "@glob_files" eq "a_dej")) {
+	print "not ";
+    }
+    print "ok 13\n";
+    chdir $cwd
+	or die "Could not chdir back to $cwd: $!";
+}
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version        : 1.0
# Date generated      : Fri Feb  2 22:19:37 2007
# Generated by        : makepatch 2.03
# Recurse directories : Yes
# Excluded files      : (\A|/).*\~\Z
#                       (\A|/).*\.a\Z
#                       (\A|/).*\.bak\Z
#                       (\A|/).*\.BAK\Z
#                       (\A|/).*\.elc\Z
#                       (\A|/).*\.exe\Z
#                       (\A|/).*\.gz\Z
#                       (\A|/).*\.ln\Z
#                       (\A|/).*\.o\Z
#                       (\A|/).*\.obj\Z
#                       (\A|/).*\.olb\Z
#                       (\A|/).*\.old\Z
#                       (\A|/).*\.orig\Z
#                       (\A|/).*\.rej\Z
#                       (\A|/).*\.so\Z
#                       (\A|/).*\.Z\Z
#                       (\A|/)\.del\-.*\Z
#                       (\A|/)\.make\.state\Z
#                       (\A|/)\.nse_depinfo\Z
#                       (\A|/)core\Z
#                       (\A|/)tags\Z
#                       (\A|/)TAGS\Z
# v 'patchlevel.h' 4732 1160388693 33060
# p 'ext/File/Glob/bsd_glob.c' 33190 1170450352 0100444
# p 'ext/File/Glob/t/basic.t' 4491 1170451122 0100555
#### End of ApplyPatch data ####

#### End of Patch kit [created: Fri Feb  2 22:19:37 2007] ####
#### Patch checksum: 107 3431 27532 ####
#### Checksum: 125 4056 13566 ####

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2007

From @eserte

--
Slaven Rezic - slaven <at> rezic <dot> de

  Berlin Perl Mongers - http​://berlin.pm.org

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2007

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2007

From @nwc10

On Fri, Feb 02, 2007 at 11​:08​:28PM +0100, Slaven Rezic wrote​:

I compared the bsd_glob.c with FreeBSD 6.1's lib/libc/gen/glob.c and
of the ~150 differences one looked very promising and indeed seems to
fix the problem. Attached is the patch including a new (and hopefully
portable) test case.

Thanks, applied (change 30103)

Nicholas Clark

@p5pRT
Copy link
Author

p5pRT commented Mar 20, 2007

@smpeters - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant