Bug 29449

Summary: Limit length of specified fields in LogFormat
Product: Apache httpd-2 Reporter: Rici Lake <rici>
Component: mod_log_configAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED LATER    
Severity: enhancement Keywords: MassUpdate, PatchAvailable
Priority: P3    
Version: 2.0.49   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Rici Lake 2004-06-09 01:30:09 UTC
The following patch enhances mod_log_config in order to allow substitutions such as "%.200U" in order 
to limit the impact on access logs of the enormous HTTP requests which are floating around these days. 
It is strictly upwards compatible as far as I can see, and has minimal performance impact.

The .<ddd> modifier can occur in any % expansion; .0 is equivalent to "unlimited", which is, of course,
the default.

--- httpd-2.0.49-orig/modules/loggers/mod_log_config.c  Wed Mar  3 06:07:50 2004
+++ httpd-2.0.49/modules/loggers/mod_log_config.c       Tue Jun  8 11:07:41 2004
@@ -271,6 +271,7 @@
     char *arg;
     int condition_sense;
     int want_orig;
+    apr_size_t max_size;
     apr_array_header_t *conditions;
 } log_format_item;

@@ -617,6 +618,7 @@

     it->func = constant_item;
     it->conditions = NULL;
+    it->max_size = 0;

     s = *sa;
     while (*s && *s != '%') {
@@ -683,6 +685,7 @@
     ++s;
     it->condition_sense = 0;
     it->conditions = NULL;
+    it->max_size = 0;

     if (*s == '%') {
         it->arg = "%";
@@ -742,7 +745,13 @@
             }
             *(int *) apr_array_push(it->conditions) = i;
             break;
-
+        case '.':
+            i = 0;
+            while (apr_isdigit(*++s)) {
+                i = i * 10 + (*s) - '0';
+            }
+            it->max_size = i;
+            break;
         default:
             handler = (ap_log_handler *)apr_hash_get(log_hash, s++, 1);
             if (!handler) {
@@ -836,6 +845,7 @@
     request_rec *orig;
     int i;
     apr_size_t len = 0;
+    apr_size_t itemlen;
     apr_array_header_t *format;
     char *envar;
     apr_status_t rv;
@@ -881,7 +891,11 @@
     }

     for (i = 0; i < format->nelts; ++i) {
-        len += strl[i] = strlen(strs[i]);
+        itemlen = strlen(strs[i]);
+        if (items[i].max_size != 0 && items[i].max_size < itemlen) {
+            itemlen = items[i].max_size;
+        }
+        len += strl[i] = itemlen;
     }
     if (!log_writer) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, APR_EGENERAL, r,
Comment 1 William A. Rowe Jr. 2018-11-07 21:09:53 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.