From b2d154535bf3b576fcdeab9ca14474b40e8f01fb Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Sat, 3 Jan 2004 15:33:41 +0000 Subject: [PATCH] Make forensic logging EBCDIC-safe. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@102153 13f79535-47bb-0310-9956-ffa450edef68 --- modules/loggers/mod_log_forensic.c | 5 +++-- server/gen_test_char.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/loggers/mod_log_forensic.c b/modules/loggers/mod_log_forensic.c index a96b213102..95157f202b 100644 --- a/modules/loggers/mod_log_forensic.c +++ b/modules/loggers/mod_log_forensic.c @@ -75,6 +75,7 @@ #include "apr_atomic.h" #include #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; } diff --git a/server/gen_test_char.c b/server/gen_test_char.c index 83d7b4bc02..d37ba6d9b6 100644 --- a/server/gen_test_char.c +++ b/server/gen_test_char.c @@ -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) ? ',' : ' '); } -- 2.50.1