svn commit: r1935014 - in httpd/httpd/trunk: include modules/proxy server
[email protected] Fri, 05 Jun 2026 10:17:58 -0000
| Newsgroups | gmane.comp.apache.cvs |
|---|---|
| Message-ID | <178065467891.3073510.2463359474636288396@svn03-he-fi> |
Author: covener
Date: Fri Jun 5 10:17:58 2026
New Revision: 1935014
Log:
ap_regname: restrict to reasonable captures
Modified:
httpd/httpd/trunk/include/ap_regex.h
httpd/httpd/trunk/modules/proxy/mod_proxy.c
httpd/httpd/trunk/server/core.c
httpd/httpd/trunk/server/util_pcre.c
Modified: httpd/httpd/trunk/include/ap_regex.h
==============================================================================
--- httpd/httpd/trunk/include/ap_regex.h Fri Jun 5 10:13:46 2026 (r1935013)
+++ httpd/httpd/trunk/include/ap_regex.h Fri Jun 5 10:17:58 2026 (r1935014)
@@ -228,6 +228,8 @@ AP_DECLARE(apr_size_t) ap_regerror(int e
* @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,
Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c Fri Jun 5 10:13:46 2026 (r1935013)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Fri Jun 5 10:17:58 2026 (r1935014)
@@ -2945,7 +2945,9 @@ static const char *proxysection(cmd_parm
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);
Modified: httpd/httpd/trunk/server/core.c
==============================================================================
--- httpd/httpd/trunk/server/core.c Fri Jun 5 10:13:46 2026 (r1935013)
+++ httpd/httpd/trunk/server/core.c Fri Jun 5 10:17:58 2026 (r1935014)
@@ -2600,7 +2600,9 @@ static const char *dirsection(cmd_parms
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
@@ -2685,7 +2687,9 @@ static const char *urlsection(cmd_parms
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);
@@ -2776,7 +2780,9 @@ static const char *filesection(cmd_parms
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);
Modified: httpd/httpd/trunk/server/util_pcre.c
==============================================================================
--- httpd/httpd/trunk/server/util_pcre.c Fri Jun 5 10:13:46 2026 (r1935013)
+++ httpd/httpd/trunk/server/util_pcre.c Fri Jun 5 10:17:58 2026 (r1935014)
@@ -590,7 +590,16 @@ AP_DECLARE(int) ap_regname(const ap_rege
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);
}