Fix few globbing problems

This commit is contained in:
vcrhonek 2009-11-04 13:14:27 +00:00
parent 2d2c0edb5d
commit fa722a75f7
2 changed files with 47 additions and 39 deletions

View File

@ -1,6 +1,6 @@
diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
--- tcsh-6.17.00/sh.glob.c.glob-automount 2008-06-19 17:20:56.000000000 +0200 --- tcsh-6.17.00/sh.glob.c.glob-automount 2008-06-19 17:20:56.000000000 +0200
+++ tcsh-6.17.00/sh.glob.c 2009-10-19 16:51:39.000000000 +0200 +++ tcsh-6.17.00/sh.glob.c 2009-11-04 13:58:09.000000000 +0100
@@ -423,6 +423,14 @@ handleone(Char *str, Char **vl, int acti @@ -423,6 +423,14 @@ handleone(Char *str, Char **vl, int acti
return (str); return (str);
} }
@ -16,7 +16,7 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
static Char ** static Char **
libglob(Char **vl) libglob(Char **vl)
{ {
@@ -430,6 +438,12 @@ libglob(Char **vl) @@ -430,6 +438,13 @@ libglob(Char **vl)
glob_t globv; glob_t globv;
char *ptr; char *ptr;
int nonomatch = adrof(STRnonomatch) != 0, magic = 0, match = 0; int nonomatch = adrof(STRnonomatch) != 0, magic = 0, match = 0;
@ -26,10 +26,11 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ char **sres; + char **sres;
+ char **res; + char **res;
+ int size = GLOBSPACE; + int size = GLOBSPACE;
+ int cglob = 0, fglob = 0;
if (!vl || !vl[0]) if (!vl || !vl[0])
return(vl); return(vl);
@@ -438,35 +452,124 @@ libglob(Char **vl) @@ -438,35 +453,126 @@ libglob(Char **vl)
globv.gl_pathv = 0; globv.gl_pathv = 0;
globv.gl_pathc = 0; globv.gl_pathc = 0;
@ -40,18 +41,7 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
gflgs |= GLOB_NOCHECK; gflgs |= GLOB_NOCHECK;
do { do {
+ ptr = short2str(*vl); - ptr = short2qstr(*vl);
+ if (!any(ptr, '?') && !any(ptr, '*') && !any(ptr, '[') && !any(ptr, ']'))
+ {
+ if (snowc == NULL)
+ snowc = nowc = (Char **) xmalloc((size_t) ((blklen(vl) + 1) * sizeof(Char *)));
+ *nowc++ = SAVE(ptr);
+ *nowc = NULL;
+
+ continue;
+
+ }
ptr = short2qstr(*vl);
- switch (glob(ptr, gflgs, 0, &globv)) { - switch (glob(ptr, gflgs, 0, &globv)) {
- case GLOB_ABEND: - case GLOB_ABEND:
- globfree(&globv); - globfree(&globv);
@ -64,6 +54,24 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
- /* NOTREACHED */ - /* NOTREACHED */
- default: - default:
- break; - break;
- }
- if (globv.gl_flags & GLOB_MAGCHAR) {
- match |= (globv.gl_matchc != 0);
- magic = 1;
+ ptr = short2qstr(*vl);
+ if (!any(ptr, '?') && !any(ptr, '*') && !any(ptr, '[') && !any(ptr, ']'))
+ {
+ ptr = short2str(*vl);
+ if (snowc == NULL)
+ snowc = nowc = (Char **) xmalloc((size_t) ((blklen(vl) + 1) * sizeof(Char *)));
+ *nowc++ = SAVE(ptr);
+ *nowc = NULL;
+
+ continue;
+
+ }
+ else
+ cglob++;
+ switch (glob(ptr, gflgs, 0, &globv)) { + switch (glob(ptr, gflgs, 0, &globv)) {
+ case GLOB_ABEND: + case GLOB_ABEND:
+ globfree(&globv); + globfree(&globv);
@ -87,10 +95,10 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ +
+ if (snowc != NULL) + if (snowc != NULL)
+ { + {
+ while ((blklen(sres) + blklen(snowc)) >= size) { + while ((blklen(sres) + blklen(snowc)) >= size) {
+ size += GLOBSPACE; + size += GLOBSPACE;
+ sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *))); + sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *)));
+ } + }
+ +
+ if (blklen(sres) == 0) + if (blklen(sres) == 0)
+ { + {
@ -108,10 +116,10 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ +
+ if (globres != NULL) + if (globres != NULL)
+ { + {
+ while ((blklen(sres) + blklen(globres)) >= size) { + while ((blklen(sres) + blklen(globres)) >= size) {
+ size += GLOBSPACE; + size += GLOBSPACE;
+ sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *))); + sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *)));
+ } + }
+ +
+ if (blklen(sres) == 0) + if (blklen(sres) == 0)
+ { + {
@ -123,18 +131,12 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ res = blkend(sres); + res = blkend(sres);
+ res = blkcpy(res, globres); + res = blkcpy(res, globres);
+ } + }
+ xfree(globres); + xfree(globres);
+ globres = NULL; + globres = NULL;
}
- if (globv.gl_flags & GLOB_MAGCHAR) {
- match |= (globv.gl_matchc != 0);
- magic = 1;
+ else
+ {
+ globfree(&globv);
+ return NULL;
} }
- gflgs |= GLOB_APPEND; - gflgs |= GLOB_APPEND;
+ else
+ fglob++;
+ +
+ globfree(&globv); + globfree(&globv);
} }
@ -146,10 +148,10 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ +
+ if (snowc != NULL) + if (snowc != NULL)
+ { + {
+ while ((blklen(sres) + blklen(snowc)) >= size) { + while ((blklen(sres) + blklen(snowc)) >= size) {
+ size += GLOBSPACE; + size += GLOBSPACE;
+ sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *))); + sres = (Char **) xrealloc((ptr_t) sres, (size_t) (size * sizeof(Char *)));
+ } + }
+ +
+ if (blklen(sres) == 0) + if (blklen(sres) == 0)
+ { + {
@ -165,8 +167,11 @@ diff -up tcsh-6.17.00/sh.glob.c.glob-automount tcsh-6.17.00/sh.glob.c
+ snowc = NULL; + snowc = NULL;
+ } + }
+ +
+ if ((cglob != 0) && (cglob == fglob))
+ return NULL;
+
+ if (blklen(sres) != 0) + if (blklen(sres) != 0)
+ vl = saveblk(sres); + vl = saveblk(sres);
+ else + else
+ vl = NULL; + vl = NULL;
+ +

View File

@ -3,7 +3,7 @@
Summary: An enhanced version of csh, the C shell Summary: An enhanced version of csh, the C shell
Name: tcsh Name: tcsh
Version: 6.17 Version: 6.17
Release: 4%{?dist} Release: 5%{?dist}
License: BSD License: BSD
Group: System Environment/Shells Group: System Environment/Shells
Source: ftp://ftp.astron.com/pub/tcsh/%{name}-%{version}.00.tar.gz Source: ftp://ftp.astron.com/pub/tcsh/%{name}-%{version}.00.tar.gz
@ -126,6 +126,9 @@ fi
%{_mandir}/man1/*.1* %{_mandir}/man1/*.1*
%changelog %changelog
* Wed Nov 4 2009 Vitezslav Crhonek <vcrhonek@redhat.com> - 6.17-5
- Fix few globbing problems
* Mon Oct 19 2009 Vitezslav Crhonek <vcrhonek@redhat.com> - 6.17-4 * Mon Oct 19 2009 Vitezslav Crhonek <vcrhonek@redhat.com> - 6.17-4
- Fix tcsh globbing causing bad automount - Fix tcsh globbing causing bad automount
- Fix truncated history file after network crash - Fix truncated history file after network crash