From: Ben Laurie Date: Sat, 3 Jan 2004 16:53:30 +0000 (+0000) Subject: Make forensic logging EBCDIC safe. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dd7c30ca8635b81e5633f74fed8be8404beba1d;p=thirdparty%2Fapache%2Fhttpd.git Make forensic logging EBCDIC safe. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@102160 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/main/gen_test_char.c b/src/main/gen_test_char.c index d310dc55624..589ce8ef73a 100644 --- a/src/main/gen_test_char.c +++ b/src/main/gen_test_char.c @@ -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) diff --git a/src/modules/standard/mod_log_forensic.c b/src/modules/standard/mod_log_forensic.c index e24467c0704..72416db5cd2 100644 --- a/src/modules/standard/mod_log_forensic.c +++ b/src/modules/standard/mod_log_forensic.c @@ -72,6 +72,7 @@ #include "http_config.h" #include "http_log.h" #include +#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; }