summaryrefslogtreecommitdiff
path: root/rpmio/rpmglob.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpmio/rpmglob.c')
-rw-r--r--rpmio/rpmglob.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/rpmio/rpmglob.c b/rpmio/rpmglob.c
index 4fc106daf..da5493d75 100644
--- a/rpmio/rpmglob.c
+++ b/rpmio/rpmglob.c
@@ -124,30 +124,15 @@ static inline const char *next_brace_sub(const char *begin)
unsigned int depth = 0;
const char *cp = begin;
- while (1) {
- if (depth == 0) {
- if (*cp != ',' && *cp != '}' && *cp != '\0') {
- if (*cp == '{')
- ++depth;
- ++cp;
- continue;
- }
- } else {
- while (*cp != '\0' && (*cp != '}' || depth > 0)) {
- if (*cp == '}')
- --depth;
- ++cp;
- }
- if (*cp == '\0')
- /* An incorrectly terminated brace expression. */
- return NULL;
+ while (*cp != '\0') {
+ if ((*cp == '}' && depth-- == 0) || (*cp == ',' && depth == 0))
+ break;
- continue;
- }
- break;
+ if (*cp++ == '{')
+ depth++;
}
- return cp;
+ return *cp != '\0' ? cp : NULL;
}
static int __glob_pattern_p(const char *pattern, int quote);
@@ -352,7 +337,7 @@ glob(const char *pattern, int flags,
user_name = dirname + 1;
else {
char *newp;
- newp = (char *) alloca(end_name - dirname);
+ newp = (char *) alloca(end_name - dirname + 1);
*((char *) mempcpy(newp, dirname + 1, end_name - dirname))
= '\0';
user_name = newp;
@@ -649,7 +634,7 @@ static int prefix_array(const char *dirname, char **array, size_t n)
static int __glob_pattern_p(const char *pattern, int quote)
{
register const char *p;
- int open = 0;
+ int openBrackets = 0;
for (p = pattern; *p != '\0'; ++p)
switch (*p) {
@@ -663,11 +648,11 @@ static int __glob_pattern_p(const char *pattern, int quote)
break;
case '[':
- open = 1;
+ openBrackets = 1;
break;
case ']':
- if (open)
+ if (openBrackets)
return 1;
break;
}
@@ -844,6 +829,8 @@ int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr)
int i, j;
int rc;
+ gflags |= GLOB_BRACE;
+
if (home != NULL && strlen(home) > 0)
gflags |= GLOB_TILDE;
@@ -966,5 +953,32 @@ exit:
int rpmIsGlob(const char * pattern, int quote)
{
- return __glob_pattern_p(pattern, quote);
+ if (!__glob_pattern_p(pattern, quote)) {
+
+ const char *begin;
+ const char *next;
+ const char *rest;
+
+ begin = strchr(pattern, '{');
+ if (begin == NULL)
+ return 0;
+ /*
+ * Find the first sub-pattern and at the same time find the
+ * rest after the closing brace.
+ */
+ next = next_brace_sub(begin + 1);
+ if (next == NULL)
+ return 0;
+
+ /* Now find the end of the whole brace expression. */
+ rest = next;
+ while (*rest != '}') {
+ rest = next_brace_sub(rest + 1);
+ if (rest == NULL)
+ return 0;
+ }
+ /* Now we can be sure that brace expression is well-foermed. */
+ }
+
+ return 1;
}