* @param prefix An optional prefix to add to the returned names. AP_REG_MATCH
* is the recommended prefix.
* @param upper If non zero, uppercase the names
+ * @return number of regex backrefernces returned, -1 for error
+ * for successful match, AP_REG_NOMATCH otherwise
*/
AP_DECLARE(int) ap_regname(const ap_regex_t *preg,
apr_array_header_t *names, const char *prefix,
if (r) {
conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
- ap_regname(r, conf->refs, AP_REG_MATCH, 1);
+ if (ap_regname(r, conf->refs, AP_REG_MATCH, 1) < 0) {
+ return "Error processing regex captures";
+ }
}
ap_add_per_proxy_conf(cmd->server, new_dir_conf);
if (cmd->regex) {
conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
- ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1);
+ if (ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1) < 0) {
+ return "Error processing regex captures";
+ }
}
/* Make this explicit - the "/" root has 0 elements, that is, we
if (cmd->regex) {
conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
- ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1);
+ if (ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1) < 0) {
+ return "Error processing regex captures";
+ }
}
ap_add_per_url_conf(cmd->server, new_url_conf);
if (cmd->regex) {
conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
- ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1);
+ if (ap_regname(cmd->regex, conf->refs, AP_REG_MATCH, 1) < 0) {
+ return "Error processing regex captures";
+ }
}
ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf);
for (i = 0; i < namecount; i++) {
const char *offset = nametable + i * nameentrysize;
- int capture = ((offset[0] << 8) + offset[1]);
+ int capture = (((unsigned char)offset[0] << 8) + (unsigned char)offset[1]);
+
+ /* Sanity check: reject unreasonably large capture group numbers.
+ * PCRE allows up to 65535 groups, but such large numbers would
+ * cause excessive memory allocation. Limit to a reasonable maximum.
+ */
+ if (capture > 1024) {
+ return -1;
+ }
+
while (names->nelts <= capture) {
apr_array_push(names);
}