mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-15 17:12:14 +03:00
Fix build/re2.m4 file lookup
There's no such include file as "re2/re2_parse.h", and there was a typo in RE2_POSSIBLE_PATHS.
This commit is contained in:
14
build/re2.m4
14
build/re2.m4
@@ -31,7 +31,7 @@ AC_ARG_WITH(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if test "x${with_re2}" == "xno"; then
|
if test "x${with_re2}" == "xno"; then
|
||||||
AC_DEFINE(HAVE_GEOIP, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
|
AC_DEFINE(HAVE_RE2, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
|
||||||
AC_MSG_NOTICE([Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
|
AC_MSG_NOTICE([Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
|
||||||
RE2_DISABLED=yes
|
RE2_DISABLED=yes
|
||||||
else
|
else
|
||||||
@@ -48,7 +48,7 @@ else
|
|||||||
|
|
||||||
# if test "x${with_re2}" != "xyes" or test "x${with_re2}" == "xyes"; then
|
# if test "x${with_re2}" != "xyes" or test "x${with_re2}" == "xyes"; then
|
||||||
if test "x${with_re2}" == "x" || test "x${with_re2}" == "xyes"; then
|
if test "x${with_re2}" == "x" || test "x${with_re2}" == "xyes"; then
|
||||||
# Nothing about GeoIP was informed, using the pkg-config to figure things out.
|
# Nothing about RE2 was informed, using the pkg-config to figure things out.
|
||||||
if test -n "${PKG_CONFIG}"; then
|
if test -n "${PKG_CONFIG}"; then
|
||||||
RE2_PKG_NAME=""
|
RE2_PKG_NAME=""
|
||||||
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
|
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
|
||||||
@@ -58,7 +58,7 @@ else
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
AC_MSG_NOTICE([Nothing about GeoIP was informed during the configure phase. Trying to detect it on the platform...])
|
AC_MSG_NOTICE([Nothing about RE2 was informed during the configure phase. Trying to detect it on the platform...])
|
||||||
if test -n "${RE2_PKG_NAME}"; then
|
if test -n "${RE2_PKG_NAME}"; then
|
||||||
# Package was found using the pkg-config scripts
|
# Package was found using the pkg-config scripts
|
||||||
RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`"
|
RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`"
|
||||||
@@ -68,7 +68,7 @@ else
|
|||||||
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
|
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
|
||||||
else
|
else
|
||||||
# If pkg-config did not find anything useful, go over file lookup.
|
# If pkg-config did not find anything useful, go over file lookup.
|
||||||
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
|
for x in ${RE2_POSSIBLE_PATHS}; do
|
||||||
CHECK_FOR_RE2_AT(${x})
|
CHECK_FOR_RE2_AT(${x})
|
||||||
if test -n "${RE2_VERSION}"; then
|
if test -n "${RE2_VERSION}"; then
|
||||||
break
|
break
|
||||||
@@ -149,11 +149,11 @@ AC_DEFUN([CHECK_FOR_RE2_AT], [
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if test -e "${path}/include/re2_parse.h"; then
|
if test -e "${path}/include/re2.h"; then
|
||||||
re2_inc_path="${path}/include"
|
re2_inc_path="${path}/include"
|
||||||
elif test -e "${path}/re2_parse.h"; then
|
elif test -e "${path}/re2.h"; then
|
||||||
re2_inc_path="${path}"
|
re2_inc_path="${path}"
|
||||||
elif test -e "${path}/include/re2/re2_parse.h"; then
|
elif test -e "${path}/include/re2/re2.h"; then
|
||||||
re2_inc_path="${path}/include"
|
re2_inc_path="${path}/include"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -44,55 +44,71 @@ Re2::Re2(const std::string& pattern)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<RegexMatch> Re2::searchAll(const std::string& s) const {
|
static bool do_match(
|
||||||
std::list<RegexMatch> retList;
|
const RE2 &re,
|
||||||
|
const char *s,
|
||||||
|
size_t n,
|
||||||
|
RegexMatch *m,
|
||||||
|
ssize_t max_groups,
|
||||||
|
size_t offset)
|
||||||
|
{
|
||||||
|
if (m == nullptr) {
|
||||||
|
max_groups = 0;
|
||||||
|
}
|
||||||
|
|
||||||
re2::StringPiece subject(s);
|
// "+1" is required for full match (aka group 0)
|
||||||
|
size_t ngroups = re.NumberOfCapturingGroups() + 1;
|
||||||
|
if (max_groups >= 0 && max_groups < ngroups) {
|
||||||
|
ngroups = max_groups;
|
||||||
|
}
|
||||||
|
re2::StringPiece submatches[ngroups];
|
||||||
|
|
||||||
|
if (re.Match(re2::StringPiece(s, n), offset, n, RE2::UNANCHORED,
|
||||||
|
&submatches[0], ngroups)) {
|
||||||
|
if (ngroups != 0) {
|
||||||
|
RegexMatch::MatchGroupContainer groups;
|
||||||
|
groups.reserve(ngroups);
|
||||||
|
for (size_t i = 0; i < ngroups; i++) {
|
||||||
|
size_t start = submatches[i].data() - s;
|
||||||
|
std::string group = submatches[i].as_string();
|
||||||
|
groups.push_back(MatchGroup{start, std::move(group)});
|
||||||
|
}
|
||||||
|
*m = RegexMatch(std::move(groups));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<RegexMatch> Re2::searchAll(const std::string& s, bool overlapping) const {
|
||||||
|
std::vector<RegexMatch> res;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (offset <= s.size()) {
|
|
||||||
int ngroups = re.NumberOfCapturingGroups() + 1;
|
|
||||||
re2::StringPiece submatches[ngroups];
|
|
||||||
|
|
||||||
if (!re.Match(subject, offset, s.size(), RE2::UNANCHORED,
|
while (1) {
|
||||||
&submatches[0], ngroups)) {
|
RegexMatch m;
|
||||||
break;
|
bool match = do_match(re, s.data(), s.size(), &m, -1, offset);
|
||||||
}
|
if (!match) break;
|
||||||
|
|
||||||
for (int i = 0; i < ngroups; i++) {
|
if (overlapping) {
|
||||||
// N.B. StringPiece::as_string returns value, not reference
|
// start just after the beginning of the last match
|
||||||
auto match_string = submatches[i].as_string();
|
offset = m.group(0).offset + 1;
|
||||||
auto start = &submatches[i][0] - &subject[0];
|
} else {
|
||||||
retList.push_front(RegexMatch(std::move(match_string), start));
|
// start just at the end of the last match
|
||||||
}
|
offset = m.group(0).offset + m.group(0).string.size();
|
||||||
|
if (offset == m.group(0).offset) {
|
||||||
offset = (&submatches[0][0] - &subject[0]) + submatches[0].length();
|
// empty match - advance by one to not match empty string repeatedly
|
||||||
if (submatches[0].size() == 0) {
|
offset++;
|
||||||
offset++;
|
}
|
||||||
}
|
}
|
||||||
|
res.push_back(std::move(m));
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
return retList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Re2::search(const std::string& s, RegexMatch *match) const {
|
bool Re2::search(const std::string &s, RegexMatch *m, ssize_t max_groups) const {
|
||||||
re2::StringPiece subject(s);
|
return do_match(re, s.data(), s.size(), m, max_groups, 0);
|
||||||
re2::StringPiece submatches[1];
|
|
||||||
if (re.Match(subject, 0, s.size(), RE2::UNANCHORED, &submatches[0], 1)) {
|
|
||||||
// N.B. StringPiece::as_string returns value, not reference
|
|
||||||
auto match_string = submatches[0].as_string();
|
|
||||||
auto start = &submatches[0][0] - &subject[0];
|
|
||||||
*match = RegexMatch(std::move(match_string), start);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Re2::search(const std::string& s) const {
|
|
||||||
re2::StringPiece subject(s);
|
|
||||||
return re.Match(subject, 0, s.size(), RE2::UNANCHORED, NULL, 0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace backend
|
} // namespace backend
|
||||||
|
|||||||
Reference in New Issue
Block a user