]> granicus.if.org Git - apache/commitdiff
Make forensic logging EBCDIC-safe.
authorBen Laurie <ben@apache.org>
Sat, 3 Jan 2004 15:33:41 +0000 (15:33 +0000)
committerBen Laurie <ben@apache.org>
Sat, 3 Jan 2004 15:33:41 +0000 (15:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@102153 13f79535-47bb-0310-9956-ffa450edef68

modules/loggers/mod_log_forensic.c
server/gen_test_char.c

index a96b2131020ace101b8cdf6df289777b69f09c5b..95157f202b443217b8414d941fd89f0c2f08f614 100644 (file)
@@ -75,6 +75,7 @@
 #include "apr_atomic.h"
 #include <unistd.h>
 #include "http_protocol.h"
+#include "../../server/test_char.h"
 
 module AP_MODULE_DECLARE_DATA log_forensic_module;
 
@@ -156,7 +157,7 @@ static char *log_escape(char *q, const char *e, const char *p)
 {
     for ( ; *p ; ++p) {
         ap_assert(q < e);
-        if (*p < ' ' || *p >= 0x7f || *p == '|' || *p == ':' || *p == '%') {
+        if (test_char_table[*(unsigned char *)p]&T_ESCAPE_FORENSIC) {
             ap_assert(q+2 < e);
             *q++ = '%';
             sprintf(q, "%02x", *(unsigned char *)p);
@@ -184,7 +185,7 @@ static int count_string(const char *p)
     int n;
 
     for (n = 0 ; *p ; ++p, ++n)
-        if (*p < ' ' || *p >= 0x7f || *p == '|' || *p == ':' || *p == '%')
+        if (test_char_table[*(unsigned char *)p]&T_ESCAPE_FORENSIC)
             n += 2;
     return n;
 }
index 83d7b4bc022a7d49c81e42b4d6e67601f5df3b93..d37ba6d9b6cd1f304fedff62030e75e290a10781 100644 (file)
@@ -74,6 +74,7 @@
 #define T_OS_ESCAPE_PATH      (0x04)
 #define T_HTTP_TOKEN_STOP     (0x08)
 #define T_ESCAPE_LOGITEM      (0x10)
+#define T_ESCAPE_FORENSIC     (0x20)
 
 int main(int argc, char *argv[])
 {
@@ -87,6 +88,7 @@ int main(int argc, char *argv[])
            "#define T_OS_ESCAPE_PATH       (%u)\n"
            "#define T_HTTP_TOKEN_STOP      (%u)\n"
            "#define T_ESCAPE_LOGITEM       (%u)\n"
+           "#define T_ESCAPE_FORENSIC      (%u)\n"
            "\n"
            "static const unsigned char test_char_table[256] = {\n"
            "    0,",
@@ -94,7 +96,8 @@ int main(int argc, char *argv[])
            T_ESCAPE_PATH_SEGMENT,
            T_OS_ESCAPE_PATH,
            T_HTTP_TOKEN_STOP,
-           T_ESCAPE_LOGITEM);
+           T_ESCAPE_LOGITEM,
+           T_ESCAPE_FORENSIC);
 
     /* we explicitly dealt with NUL above
      * in case some strchr() do bogosity with it */
@@ -147,6 +150,14 @@ int main(int argc, char *argv[])
             flags |= T_ESCAPE_LOGITEM;
         }
 
+        /* For forensic logging, scape all control characters, top bit set,
+         * :, | (used as delimiters) and % (used for escaping).
+         */
+        if (!apr_isprint(c) || c == ':' || c == '|' || c == '%'
+            || apr_iscntrl(c)) {
+            flags |= T_ESCAPE_FORENSIC;
+        }
+
         printf("%u%c", flags, (c < 255) ? ',' : ' ');
     }