return (ARCHIVE_FATAL);
}
+static int
+error_pattern(struct archive_match *a)
+{
+ archive_set_error(&(a->archive), EINVAL, "Failed to apply pattern");
+ a->archive.state = ARCHIVE_STATE_FATAL;
+ return (ARCHIVE_FATAL);
+}
+
/*
* Create an ARCHIVE_MATCH object.
*/
#else
r = path_excluded(a, 1, archive_entry_pathname(entry));
#endif
+ if (r < 0)
+ return (error_pattern(a));
if (r != 0)
return (r);
}
struct archive_entry *entry)
{
struct archive_match *a;
+ int r;
archive_check_magic(_a, ARCHIVE_MATCH_MAGIC,
ARCHIVE_STATE_NEW, "archive_match_path_excluded");
if ((a->setflag & PATTERN_IS_SET) == 0)
return (0);
#if defined(_WIN32) && !defined(__CYGWIN__)
- return (path_excluded(a, 0, archive_entry_pathname_w(entry)));
+ r = path_excluded(a, 0, archive_entry_pathname_w(entry));
#else
- return (path_excluded(a, 1, archive_entry_pathname(entry)));
+ r = path_excluded(a, 1, archive_entry_pathname(entry));
#endif
+ if (r < 0)
+ return (error_pattern(a));
+ return (r);
}
/*
#include "archive_pathmatch.h"
+#define MAX_RECURSION 100
+
/*
* Check whether a character 'c' is matched by a list specification [...]:
* * Leading '!' or '^' negates the class.
}
static int
-pm(const char *p, const char *s, int flags)
+pm(const char *p, const char *s, int flags, int depth)
{
const char *end;
+ int r;
+
+ if (depth > MAX_RECURSION)
+ return (-1);
/*
* Ignore leading './', './/', '././', etc.
if (*p == '\0')
return (1);
while (*s) {
- if (pm(p, s, flags))
- return (1);
+ r = pm(p, s, flags, depth + 1);
+ if (r)
+ return (r);
++s;
}
return (0);
}
static int
-pm_w(const wchar_t *p, const wchar_t *s, int flags)
+pm_w(const wchar_t *p, const wchar_t *s, int flags, int depth)
{
const wchar_t *end;
+ int r;
+
+ if (depth > MAX_RECURSION)
+ return (-1);
/*
* Ignore leading './', './/', '././', etc.
if (*p == L'\0')
return (1);
while (*s) {
- if (pm_w(p, s, flags))
- return (1);
+ r = pm_w(p, s, flags, depth + 1);
+ if (r)
+ return (r);
++s;
}
return (0);
++p;
while (*s == '/')
++s;
- return (pm(p, s, flags));
+ return (pm(p, s, flags, 0));
}
/* If start is unanchored, try to match start of each path element. */
if (flags & PATHMATCH_NO_ANCHOR_START) {
for ( ; s != NULL; s = strchr(s, '/')) {
+ int r;
+
if (*s == '/')
s++;
- if (pm(p, s, flags))
- return (1);
+ r = pm(p, s, flags, 0);
+ if (r)
+ return (r);
}
return (0);
}
/* Default: Match from beginning. */
- return (pm(p, s, flags));
+ return (pm(p, s, flags, 0));
}
int
++p;
while (*s == L'/')
++s;
- return (pm_w(p, s, flags));
+ return (pm_w(p, s, flags, 0));
}
/* If start is unanchored, try to match start of each path element. */
if (flags & PATHMATCH_NO_ANCHOR_START) {
for ( ; s != NULL; s = wcschr(s, L'/')) {
+ int r;
+
if (*s == L'/')
s++;
- if (pm_w(p, s, flags))
- return (1);
+ r = pm_w(p, s, flags, 0);
+ if (r)
+ return (r);
}
return (0);
}
/* Default: Match from beginning. */
- return (pm_w(p, s, flags));
+ return (pm_w(p, s, flags, 0));
}