]> granicus.if.org Git - apache/commitdiff
- Add another check during ErrorLogFormat parsing
authorStefan Fritsch <sf@apache.org>
Mon, 6 Sep 2010 18:53:38 +0000 (18:53 +0000)
committerStefan Fritsch <sf@apache.org>
Mon, 6 Sep 2010 18:53:38 +0000 (18:53 +0000)
- Simplify code (including Ruediger's suggestions)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@993120 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
server/core.c
server/log.c

diff --git a/CHANGES b/CHANGES
index d90f587be84fa7162c4ea2c7fde9d66a0fdfa1b7..f48ea7e386ea3b4099a07c345dcbf9fa8320e011 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,7 +5,7 @@ Changes with Apache 2.3.9
   *) core: Add ErrorLogFormat to allow configuring error log format, including
      additional information that is logged once per connection or request. Add
      error log IDs for connections and request to allow correlating error log
-     lines and the corresponding access log entry.
+     lines and the corresponding access log entry. [Stefan Fritsch]
 
   *) core: Disable sendfile by default. [Stefan Fritsch]
 
index 25f307f5b05a7825bcdf32a1773b293894aa1b80..b395238696a0b8152281d22830d0aab1625cec6d 100644 (file)
@@ -3272,6 +3272,10 @@ static apr_array_header_t *parse_errorlog_string(apr_pool_t *p,
             }
             seen_msg_fmt = 1;
         }
+        if (want_msg_fmt && item->flags & AP_ERRORLOG_FLAG_REQUIRED) {
+            *err = "The '+' flag cannot be used in the main error log format";
+            return NULL;
+        }
     }
 
     if (want_msg_fmt && !seen_msg_fmt) {
@@ -3299,7 +3303,7 @@ static const char *set_errorlog_format(cmd_parms *cmd, void *dummy,
                                                   sizeof(apr_array_header_t *));
         }
 
-        if (arg2 && *arg2) {
+        if (*arg2) {
             apr_array_header_t **e;
             e = (apr_array_header_t **) apr_array_push(conf->error_log_conn);
             *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
@@ -3311,7 +3315,7 @@ static const char *set_errorlog_format(cmd_parms *cmd, void *dummy,
                                                  sizeof(apr_array_header_t *));
         }
 
-        if (arg2 && *arg2) {
+        if (*arg2) {
             apr_array_header_t **e;
             e = (apr_array_header_t **) apr_array_push(conf->error_log_req);
             *e = parse_errorlog_string(cmd->pool, arg2, &err_string, 0);
index 42d711744acc36317b5eda0d6a64889c5d086207..e865628183659012d0a92760eee213cf00322d20 100644 (file)
@@ -712,25 +712,24 @@ static int log_apr_status(const ap_errorlog_info *info, const char *arg,
                           char *buf, int buflen)
 {
     apr_status_t status = info->status;
-    int len = 0;
+    int len;
     if (!status)
         return 0;
 
     if (status < APR_OS_START_EAIERR) {
-        len += apr_snprintf(buf + len, buflen - len,
-                            "(%d)", status);
+        len = apr_snprintf(buf, buflen, "(%d)", status);
     }
     else if (status < APR_OS_START_SYSERR) {
-        len += apr_snprintf(buf + len, buflen - len,
-                            "(EAI %d)", status - APR_OS_START_EAIERR);
+        len = apr_snprintf(buf, buflen, "(EAI %d)",
+                           status - APR_OS_START_EAIERR);
     }
     else if (status < 100000 + APR_OS_START_SYSERR) {
-        len += apr_snprintf(buf + len, buflen - len,
-                            "(OS %d)", status - APR_OS_START_SYSERR);
+        len = apr_snprintf(buf, buflen, "(OS %d)",
+                           status - APR_OS_START_SYSERR);
     }
     else {
-        len += apr_snprintf(buf + len, buflen - len,
-                            "(os 0x%08x)", status - APR_OS_START_SYSERR);
+        len = apr_snprintf(buf, buflen, "(os 0x%08x)",
+                           status - APR_OS_START_SYSERR);
     }
     apr_strerror(status, buf + len, buflen - len);
     len += strlen(buf + len);
@@ -813,7 +812,7 @@ static void add_log_id(const conn_rec *c, const request_rec *r)
         id ^= tmp;
     }
 #if APR_HAS_THREADS
-    if (c) {
+    {
         apr_uintptr_t tmp2 = (apr_uintptr_t)c->current_thread;
         tmp = tmp2;
         tmp = tmp << 32;
@@ -821,14 +820,15 @@ static void add_log_id(const conn_rec *c, const request_rec *r)
     }
 #endif
 
-    /*
-     * The apr-util docs wrongly states encoded strings are not 0-terminated.
-     * Let's be save and allocate an additional byte.
-     */
-    len = 1 + apr_base64_encode_len(sizeof(id));
+    len = apr_base64_encode_len(sizeof(id));
     encoded = apr_palloc(r ? r->pool : c->pool, len);
     apr_base64_encode(encoded, (char *)&id, sizeof(id));
-    encoded[11] = '\0'; /* omit last char which is always '=' */
+
+    /*
+     * Only the first 11 chars are significant, the last (12th) char is
+     * always '='.
+     */
+    encoded[11] = '\0'; 
 
     /* need to cast const away */
     if (r) {