MXS-2785: Report PCRE2 errors

The substitution string could cause errors.
This commit is contained in:
Markus Mäkelä
2019-12-09 14:19:15 +02:00
parent b32546e839
commit e36c7efa25
4 changed files with 39 additions and 7 deletions

View File

@ -248,8 +248,12 @@ bool mxs_pcre2_check_match_exclude(pcre2_code* re_match,
namespace maxscale
{
std::string pcre2_substitute(pcre2_code* re, const std::string& subject, const std::string& replace)
std::string pcre2_substitute(pcre2_code* re,
const std::string& subject,
const std::string& replace,
std::string* error)
{
mxb_assert(re);
std::string rval = subject;
size_t size_tmp = rval.size();
int rc;
@ -263,7 +267,21 @@ std::string pcre2_substitute(pcre2_code* re, const std::string& subject, const s
size_tmp = rval.size();
}
rval.resize(size_tmp);
if (rc < 0)
{
if (error)
{
char errbuf[1024];
pcre2_get_error_message(rc, (PCRE2_UCHAR*)errbuf, sizeof(errbuf));
*error = errbuf;
}
rval.clear();
}
else
{
rval.resize(size_tmp);
}
return rval;
}