Author: ache
Date: Tue Jul 19 00:25:27 2016
New Revision: 303014
URL: https://svnweb.freebsd.org/changeset/base/303014

Log:
  1) Don't protect \/ and \. even if user say so. They are not special chars
  in any case and needed for further processing. For ~ expansion too.
  
  2) Don't terminate *pathend with / when GLOB_LIMIT_STAT is reached, it will
  be not visible outside in any case since error is returned.
  
  3) Cosmetic: change if expression to better reflect its semantic.

Modified:
  head/lib/libc/gen/glob.c

Modified: head/lib/libc/gen/glob.c
==============================================================================
--- head/lib/libc/gen/glob.c    Mon Jul 18 20:24:13 2016        (r303013)
+++ head/lib/libc/gen/glob.c    Tue Jul 19 00:25:27 2016        (r303014)
@@ -244,7 +244,8 @@ glob(const char * __restrict pattern, in
                                return (GLOB_NOMATCH);
                        else if (clen == 0)
                                break;
-                       *bufnext++ = wc | prot;
+                       *bufnext++ = wc | ((wc != DOT && wc != SEP) ?
+                           prot : 0);
                        patnext += clen;
                }
        }
@@ -478,8 +479,8 @@ globtilde(const Char *pattern, Char *pat
                return (NULL);
 
        dc = wbuf;
-       for (b = patbuf; b < eb && *dc != EOS; *b++ = *dc++ | M_PROTECT)
-               continue;
+       for (b = patbuf; b < eb && *dc != EOS; b++, dc++)
+               *b = *dc | ((*dc != DOT && *dc != SEP) ? M_PROTECT : 0);
        if (*dc != EOS)
                return (NULL);
 
@@ -642,10 +643,6 @@ glob2(Char *pathbuf, Char *pathend, Char
                        if ((pglob->gl_flags & GLOB_LIMIT) &&
                            limit->l_stat_cnt++ >= GLOB_LIMIT_STAT) {
                                errno = 0;
-                               if (pathend + 1 > pathend_last)
-                                       return (GLOB_NOSPACE);
-                               *pathend++ = SEP;
-                               *pathend = EOS;
                                return (GLOB_NOSPACE);
                        }
                        if (((pglob->gl_flags & GLOB_MARK) &&
@@ -886,7 +883,7 @@ match(Char *name, Char *pat, Char *paten
                        ok = 0;
                        if ((k = *name++) == EOS)
                                return (0);
-                       if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
+                       if ((negate_range = ((*pat & M_MASK) == M_NOT)) != 0)
                                ++pat;
                        while (((c = *pat++) & M_MASK) != M_END)
                                if ((*pat & M_MASK) == M_RNG) {
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to