|
Lubos Kardos |
ad8c42 |
From 630a0970df46df6cc96a68349cf4e08d8b4ca772 Mon Sep 17 00:00:00 2001
|
|
Lubos Kardos |
ad8c42 |
From: Lubos Kardos <lkardos@redhat.com>
|
|
Lubos Kardos |
ad8c42 |
Date: Mon, 3 Aug 2015 16:51:11 +0200
|
|
Lubos Kardos |
ad8c42 |
Subject: [PATCH 1/2] Modify rpmIsGlob() to be more precise.
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
Now rpmIsGlob() checks if braces expansion pattern is well formed and
|
|
Lubos Kardos |
ad8c42 |
not only if it contains opening and closing brace. The checking
|
|
Lubos Kardos |
ad8c42 |
procedure is same as procedure in glob() so rpmIsGlob() and glob() are
|
|
Lubos Kardos |
ad8c42 |
now compatible.
|
|
Lubos Kardos |
ad8c42 |
---
|
|
Lubos Kardos |
ad8c42 |
rpmio/rpmglob.c | 57 ++++++++++++++++++++++++++++++++-------------------------
|
|
Lubos Kardos |
ad8c42 |
1 file changed, 32 insertions(+), 25 deletions(-)
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
diff --git a/rpmio/rpmglob.c b/rpmio/rpmglob.c
|
|
Lubos Kardos |
ad8c42 |
index 597ac5c..0c6b0a3 100644
|
|
Lubos Kardos |
ad8c42 |
--- a/rpmio/rpmglob.c
|
|
Lubos Kardos |
ad8c42 |
+++ b/rpmio/rpmglob.c
|
|
Lubos Kardos |
ad8c42 |
@@ -150,7 +150,7 @@ static inline const char *next_brace_sub(const char *begin)
|
|
Lubos Kardos |
ad8c42 |
return cp;
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
-static int __glob_pattern_p(const char *pattern, int flags);
|
|
Lubos Kardos |
ad8c42 |
+static int __glob_pattern_p(const char *pattern, int quote);
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
/* Do glob searching for PATTERN, placing results in PGLOB.
|
|
Lubos Kardos |
ad8c42 |
The bits defined above may be set in FLAGS.
|
|
Lubos Kardos |
ad8c42 |
@@ -419,7 +419,7 @@ glob(const char *pattern, int flags,
|
|
Lubos Kardos |
ad8c42 |
return GLOB_NOMATCH;
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
- if (__glob_pattern_p(dirname, flags)) {
|
|
Lubos Kardos |
ad8c42 |
+ if (__glob_pattern_p(dirname, !(flags & GLOB_NOESCAPE))) {
|
|
Lubos Kardos |
ad8c42 |
/* The directory name contains metacharacters, so we
|
|
Lubos Kardos |
ad8c42 |
have to glob for the directory, and then glob for
|
|
Lubos Kardos |
ad8c42 |
the pattern in each directory found. */
|
|
Lubos Kardos |
ad8c42 |
@@ -646,11 +646,10 @@ static int prefix_array(const char *dirname, char **array, size_t n)
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
/* Return nonzero if PATTERN contains any metacharacters.
|
|
Lubos Kardos |
ad8c42 |
Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
|
|
Lubos Kardos |
ad8c42 |
-static int __glob_pattern_p(const char *pattern, int flags)
|
|
Lubos Kardos |
ad8c42 |
+static int __glob_pattern_p(const char *pattern, int quote)
|
|
Lubos Kardos |
ad8c42 |
{
|
|
Lubos Kardos |
ad8c42 |
register const char *p;
|
|
Lubos Kardos |
ad8c42 |
int openBrackets = 0;
|
|
Lubos Kardos |
ad8c42 |
- int openBraces = 0;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
for (p = pattern; *p != '\0'; ++p)
|
|
Lubos Kardos |
ad8c42 |
switch (*p) {
|
|
Lubos Kardos |
ad8c42 |
@@ -659,7 +658,7 @@ static int __glob_pattern_p(const char *pattern, int flags)
|
|
Lubos Kardos |
ad8c42 |
return 1;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
case '\\':
|
|
Lubos Kardos |
ad8c42 |
- if (!(flags & GLOB_NOESCAPE) && p[1] != '\0')
|
|
Lubos Kardos |
ad8c42 |
+ if (quote && p[1] != '\0')
|
|
Lubos Kardos |
ad8c42 |
++p;
|
|
Lubos Kardos |
ad8c42 |
break;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
@@ -671,17 +670,6 @@ static int __glob_pattern_p(const char *pattern, int flags)
|
|
Lubos Kardos |
ad8c42 |
if (openBrackets)
|
|
Lubos Kardos |
ad8c42 |
return 1;
|
|
Lubos Kardos |
ad8c42 |
break;
|
|
Lubos Kardos |
ad8c42 |
-
|
|
Lubos Kardos |
ad8c42 |
- case '{':
|
|
Lubos Kardos |
ad8c42 |
- if (flags & GLOB_BRACE)
|
|
Lubos Kardos |
ad8c42 |
- openBraces = 1;
|
|
Lubos Kardos |
ad8c42 |
- break;
|
|
Lubos Kardos |
ad8c42 |
-
|
|
Lubos Kardos |
ad8c42 |
- case '}':
|
|
Lubos Kardos |
ad8c42 |
- if (openBraces)
|
|
Lubos Kardos |
ad8c42 |
- return 1;
|
|
Lubos Kardos |
ad8c42 |
- break;
|
|
Lubos Kardos |
ad8c42 |
-
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
return 0;
|
|
Lubos Kardos |
ad8c42 |
@@ -706,7 +694,7 @@ glob_in_dir(const char *pattern, const char *directory, int flags,
|
|
Lubos Kardos |
ad8c42 |
int meta;
|
|
Lubos Kardos |
ad8c42 |
int save;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
- meta = __glob_pattern_p(pattern, flags);
|
|
Lubos Kardos |
ad8c42 |
+ meta = __glob_pattern_p(pattern, !(flags & GLOB_NOESCAPE));
|
|
Lubos Kardos |
ad8c42 |
if (meta == 0) {
|
|
Lubos Kardos |
ad8c42 |
if (flags & (GLOB_NOCHECK | GLOB_NOMAGIC))
|
|
Lubos Kardos |
ad8c42 |
/* We need not do any tests. The PATTERN contains no meta
|
|
Lubos Kardos |
ad8c42 |
@@ -888,9 +876,7 @@ int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr)
|
|
Lubos Kardos |
ad8c42 |
int dir_only = (plen > 0 && path[plen-1] == '/');
|
|
Lubos Kardos |
ad8c42 |
glob_t gl;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
- if (!local || (!rpmIsGlob(av[j], GLOB_NOESCAPE | flags) &&
|
|
Lubos Kardos |
ad8c42 |
- strchr(path, '~') == NULL)) {
|
|
Lubos Kardos |
ad8c42 |
-
|
|
Lubos Kardos |
ad8c42 |
+ if (!local || (!rpmIsGlob(av[j], 0) && strchr(path, '~') == NULL)) {
|
|
Lubos Kardos |
ad8c42 |
argvAdd(&argv, av[j]);
|
|
Lubos Kardos |
ad8c42 |
continue;
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
@@ -982,11 +968,32 @@ exit:
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
int rpmIsGlob(const char * pattern, int quote)
|
|
Lubos Kardos |
ad8c42 |
{
|
|
Lubos Kardos |
ad8c42 |
- int flags = 0;
|
|
Lubos Kardos |
ad8c42 |
- if (!quote) {
|
|
Lubos Kardos |
ad8c42 |
- flags |= GLOB_NOESCAPE;
|
|
Lubos Kardos |
ad8c42 |
+ if(!__glob_pattern_p(pattern, quote)) {
|
|
Lubos Kardos |
ad8c42 |
+
|
|
Lubos Kardos |
ad8c42 |
+ const char *begin;
|
|
Lubos Kardos |
ad8c42 |
+ const char *next;
|
|
Lubos Kardos |
ad8c42 |
+ const char *rest;
|
|
Lubos Kardos |
ad8c42 |
+
|
|
Lubos Kardos |
ad8c42 |
+ begin = strchr(pattern, '{');
|
|
Lubos Kardos |
ad8c42 |
+ if (begin == NULL)
|
|
Lubos Kardos |
ad8c42 |
+ return 0;
|
|
Lubos Kardos |
ad8c42 |
+ /*
|
|
Lubos Kardos |
ad8c42 |
+ * Find the first sub-pattern and at the same time find the
|
|
Lubos Kardos |
ad8c42 |
+ * rest after the closing brace.
|
|
Lubos Kardos |
ad8c42 |
+ */
|
|
Lubos Kardos |
ad8c42 |
+ next = next_brace_sub(begin + 1);
|
|
Lubos Kardos |
ad8c42 |
+ if (next == NULL)
|
|
Lubos Kardos |
ad8c42 |
+ return 0;
|
|
Lubos Kardos |
ad8c42 |
+
|
|
Lubos Kardos |
ad8c42 |
+ /* Now find the end of the whole brace expression. */
|
|
Lubos Kardos |
ad8c42 |
+ rest = next;
|
|
Lubos Kardos |
ad8c42 |
+ while (*rest != '}') {
|
|
Lubos Kardos |
ad8c42 |
+ rest = next_brace_sub(rest + 1);
|
|
Lubos Kardos |
ad8c42 |
+ if (rest == NULL)
|
|
Lubos Kardos |
ad8c42 |
+ return 0;
|
|
Lubos Kardos |
ad8c42 |
+ }
|
|
Lubos Kardos |
ad8c42 |
+ /* Now we can be sure that brace expression is well-foermed. */
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
- flags |= GLOB_BRACE;
|
|
Lubos Kardos |
ad8c42 |
|
|
Lubos Kardos |
ad8c42 |
- return __glob_pattern_p(pattern, flags);
|
|
Lubos Kardos |
ad8c42 |
+ return 1;
|
|
Lubos Kardos |
ad8c42 |
}
|
|
Lubos Kardos |
ad8c42 |
--
|
|
Lubos Kardos |
ad8c42 |
1.9.3
|
|
Lubos Kardos |
ad8c42 |
|