mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +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:
parent
d349fa0c56
commit
a2dc896520
14
build/re2.m4
14
build/re2.m4
@ -31,7 +31,7 @@ AC_ARG_WITH(
|
||||
)
|
||||
|
||||
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])
|
||||
RE2_DISABLED=yes
|
||||
else
|
||||
@ -48,7 +48,7 @@ else
|
||||
|
||||
# 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
|
||||
# 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
|
||||
RE2_PKG_NAME=""
|
||||
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
|
||||
@ -58,7 +58,7 @@ else
|
||||
fi
|
||||
done
|
||||
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
|
||||
# Package was found using the pkg-config scripts
|
||||
RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`"
|
||||
@ -68,7 +68,7 @@ else
|
||||
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
|
||||
else
|
||||
# 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})
|
||||
if test -n "${RE2_VERSION}"; then
|
||||
break
|
||||
@ -149,11 +149,11 @@ AC_DEFUN([CHECK_FOR_RE2_AT], [
|
||||
break
|
||||
fi
|
||||
done
|
||||
if test -e "${path}/include/re2_parse.h"; then
|
||||
if test -e "${path}/include/re2.h"; then
|
||||
re2_inc_path="${path}/include"
|
||||
elif test -e "${path}/re2_parse.h"; then
|
||||
elif test -e "${path}/re2.h"; then
|
||||
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"
|
||||
fi
|
||||
|
||||
|
@ -44,55 +44,71 @@ Re2::Re2(const std::string& pattern)
|
||||
{
|
||||
}
|
||||
|
||||
std::list<RegexMatch> Re2::searchAll(const std::string& s) const {
|
||||
std::list<RegexMatch> retList;
|
||||
static bool do_match(
|
||||
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;
|
||||
while (offset <= s.size()) {
|
||||
int ngroups = re.NumberOfCapturingGroups() + 1;
|
||||
re2::StringPiece submatches[ngroups];
|
||||
|
||||
if (!re.Match(subject, offset, s.size(), RE2::UNANCHORED,
|
||||
&submatches[0], ngroups)) {
|
||||
break;
|
||||
}
|
||||
while (1) {
|
||||
RegexMatch m;
|
||||
bool match = do_match(re, s.data(), s.size(), &m, -1, offset);
|
||||
if (!match) break;
|
||||
|
||||
for (int i = 0; i < ngroups; i++) {
|
||||
// N.B. StringPiece::as_string returns value, not reference
|
||||
auto match_string = submatches[i].as_string();
|
||||
auto start = &submatches[i][0] - &subject[0];
|
||||
retList.push_front(RegexMatch(std::move(match_string), start));
|
||||
}
|
||||
|
||||
offset = (&submatches[0][0] - &subject[0]) + submatches[0].length();
|
||||
if (submatches[0].size() == 0) {
|
||||
offset++;
|
||||
if (overlapping) {
|
||||
// start just after the beginning of the last match
|
||||
offset = m.group(0).offset + 1;
|
||||
} else {
|
||||
// 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) {
|
||||
// empty match - advance by one to not match empty string repeatedly
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
res.push_back(std::move(m));
|
||||
}
|
||||
|
||||
return retList;
|
||||
return res;
|
||||
}
|
||||
|
||||
int Re2::search(const std::string& s, RegexMatch *match) const {
|
||||
re2::StringPiece subject(s);
|
||||
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;
|
||||
}
|
||||
bool Re2::search(const std::string &s, RegexMatch *m, ssize_t max_groups) const {
|
||||
return do_match(re, s.data(), s.size(), m, max_groups, 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
|
||||
|
||||
} // namespace backend
|
||||
|
Loading…
x
Reference in New Issue
Block a user