]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Make forensic logging EBCDIC safe.
authorBen Laurie <ben@apache.org>
Sat, 3 Jan 2004 16:53:30 +0000 (16:53 +0000)
committerBen Laurie <ben@apache.org>
Sat, 3 Jan 2004 16:53:30 +0000 (16:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@102160 13f79535-47bb-0310-9956-ffa450edef68

src/main/gen_test_char.c
src/modules/standard/mod_log_forensic.c

index d310dc556245dcba3fe04b7bebdccf71a13322fe..589ce8ef73a687aa507b3b4b02493cc1fb8a3359 100644 (file)
@@ -9,6 +9,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[])
 {
@@ -22,21 +23,20 @@ int main(int argc, char *argv[])
 "#define T_OS_ESCAPE_PATH      0x%02x /* escape characters in a path or uri */\n"
 "#define T_HTTP_TOKEN_STOP     0x%02x /* find http tokens, as defined in RFC2616 */\n"
 "#define T_ESCAPE_LOGITEM      0x%02x /* filter what should go in the log file */\n"
+"#define T_ESCAPE_FORENSIC     0x%02x /* filter what should go in the forensic log */\n"
 "\n",
        T_ESCAPE_SHELL_CMD,
        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 */
-
     printf("static const unsigned char test_char_table[256] = {\n"
-          "    0x00, ");    /* print initial item */
+          "    ");
 
-    for (c = 1; c < 256; ++c) {
+    for (c = 0; c < 256; ++c) {
        flags = 0;
 
        /* escape_shell_cmd */
@@ -79,6 +79,15 @@ int main(int argc, char *argv[])
        if (!ap_isprint(c) || c == '"' || c == '\\' || ap_iscntrl(c)) {
            flags |= T_ESCAPE_LOGITEM;
        }
+
+        /* For forensic logging, escape all control characters, top bit set,
+         * :, | (used as delimiters) and % (used for escaping).
+         */
+        if (!ap_isprint(c) || c == ':' || c == '|' || c == '%'
+            || ap_iscntrl(c) || !c) {
+            flags |= T_ESCAPE_FORENSIC;
+        }
+
        printf("0x%02x%s", flags, (c < 255) ? ", " : "  ");
 
        if ((c % 8) == 7)
index e24467c070419b9b2edac496a5f81a9c924e7a4d..72416db5cd21c430a3ead2f817562087f9b5b538 100644 (file)
@@ -72,6 +72,7 @@
 #include "http_config.h"
 #include "http_log.h"
 #include <assert.h>
+#include "../../main/test_char.h"
 
 module MODULE_VAR_EXPORT log_forensic_module;
 
@@ -149,7 +150,7 @@ static char *log_escape(char *q, const char *e, const char *p)
 {
     for ( ; *p ; ++p) {
         assert(q < e);
-        if (*p < ' ' || *p >= 0x7f || *p == '|' || *p == ':' || *p == '%') {
+        if (test_char_table[*(unsigned char *)p]&T_ESCAPE_FORENSIC) {
             assert(q+2 < e);
             *q++ = '%';
             sprintf(q, "%02x", *(unsigned char *)p);
@@ -177,7 +178,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;
 }