You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by be...@apache.org on 2004/01/03 16:33:41 UTC

cvs commit: httpd-2.0/server gen_test_char.c

ben         2004/01/03 07:33:41

  Modified:    modules/loggers mod_log_forensic.c
               server   gen_test_char.c
  Log:
  Make forensic logging EBCDIC-safe.
  
  Revision  Changes    Path
  1.4       +3 -2      httpd-2.0/modules/loggers/mod_log_forensic.c
  
  Index: mod_log_forensic.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_forensic.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- mod_log_forensic.c	3 Jan 2004 14:35:21 -0000	1.3
  +++ mod_log_forensic.c	3 Jan 2004 15:33:41 -0000	1.4
  @@ -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 @@
   {
       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 @@
       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;
   }
  
  
  
  1.18      +12 -1     httpd-2.0/server/gen_test_char.c
  
  Index: gen_test_char.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/gen_test_char.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- gen_test_char.c	1 Jan 2004 13:26:23 -0000	1.17
  +++ gen_test_char.c	3 Jan 2004 15:33:41 -0000	1.18
  @@ -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 @@
              "#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 @@
              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 */
  @@ -145,6 +148,14 @@
            */
           if (!apr_isprint(c) || c == '"' || c == '\\' || apr_iscntrl(c)) {
               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) ? ',' : ' ');