in flood_pcre.c [158:228]
int flood_regexec(const flood_regex_t *preg, const char *string,
apr_size_t nmatch, flood_regmatch_t pmatch[],
int eflags)
{
int rc;
int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
int allocated_ovector = 0;
if ((eflags & FLOOD_REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
if ((eflags & FLOOD_REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
((flood_regex_t *)preg)->re_erroffset = (apr_size_t)(-1); /* Only has meaning after compile */
if (nmatch > 0)
{
if (nmatch <= POSIX_MALLOC_THRESHOLD)
{
ovector = &(small_ovector[0]);
}
else
{
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
if (ovector == NULL) return FLOOD_REG_ESPACE;
allocated_ovector = 1;
}
}
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
0, options, ovector, nmatch * 3);
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
if (rc >= 0)
{
apr_size_t i;
for (i = 0; i < (apr_size_t)rc; i++)
{
pmatch[i].rm_so = ovector[i*2];
pmatch[i].rm_eo = ovector[i*2+1];
}
if (allocated_ovector) free(ovector);
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
return 0;
}
else
{
if (allocated_ovector) free(ovector);
switch(rc)
{
case PCRE_ERROR_NOMATCH: return FLOOD_REG_NOMATCH;
case PCRE_ERROR_NULL: return FLOOD_REG_INVARG;
case PCRE_ERROR_BADOPTION: return FLOOD_REG_INVARG;
case PCRE_ERROR_BADMAGIC: return FLOOD_REG_INVARG;
case PCRE_ERROR_UNKNOWN_NODE: return FLOOD_REG_ASSERT;
case PCRE_ERROR_NOMEMORY: return FLOOD_REG_ESPACE;
#ifdef PCRE_ERROR_MATCHLIMIT
case PCRE_ERROR_MATCHLIMIT: return FLOOD_REG_ESPACE;
#endif
#ifdef PCRE_ERROR_BADUTF8
case PCRE_ERROR_BADUTF8: return FLOOD_REG_INVARG;
#endif
#ifdef PCRE_ERROR_BADUTF8_OFFSET
case PCRE_ERROR_BADUTF8_OFFSET: return FLOOD_REG_INVARG;
#endif
default: return FLOOD_REG_ASSERT;
}
}
}