~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to server/gen_test_char.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
 
2
 * contributor license agreements.  See the NOTICE file distributed with
 
3
 * this work for additional information regarding copyright ownership.
 
4
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
5
 * (the "License"); you may not use this file except in compliance with
 
6
 * the License.  You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "apr.h"
 
18
#include "apr_lib.h"
 
19
 
 
20
#if APR_HAVE_STDIO_H
 
21
#include <stdio.h>
 
22
#endif
 
23
#if APR_HAVE_STRING_H
 
24
#include <string.h>
 
25
#endif
 
26
 
 
27
/* A bunch of functions in util.c scan strings looking for certain characters.
 
28
 * To make that more efficient we encode a lookup table.
 
29
 */
 
30
#define T_ESCAPE_SHELL_CMD    (0x01)
 
31
#define T_ESCAPE_PATH_SEGMENT (0x02)
 
32
#define T_OS_ESCAPE_PATH      (0x04)
 
33
#define T_HTTP_TOKEN_STOP     (0x08)
 
34
#define T_ESCAPE_LOGITEM      (0x10)
 
35
#define T_ESCAPE_FORENSIC     (0x20)
 
36
 
 
37
int main(int argc, char *argv[])
 
38
{
 
39
    unsigned c;
 
40
    unsigned char flags;
 
41
 
 
42
    printf("/* this file is automatically generated by gen_test_char, "
 
43
           "do not edit */\n"
 
44
           "#define T_ESCAPE_SHELL_CMD     (%u)\n"
 
45
           "#define T_ESCAPE_PATH_SEGMENT  (%u)\n"
 
46
           "#define T_OS_ESCAPE_PATH       (%u)\n"
 
47
           "#define T_HTTP_TOKEN_STOP      (%u)\n"
 
48
           "#define T_ESCAPE_LOGITEM       (%u)\n"
 
49
           "#define T_ESCAPE_FORENSIC      (%u)\n"
 
50
           "\n"
 
51
           "static const unsigned char test_char_table[256] = {",
 
52
           T_ESCAPE_SHELL_CMD,
 
53
           T_ESCAPE_PATH_SEGMENT,
 
54
           T_OS_ESCAPE_PATH,
 
55
           T_HTTP_TOKEN_STOP,
 
56
           T_ESCAPE_LOGITEM,
 
57
           T_ESCAPE_FORENSIC);
 
58
 
 
59
    for (c = 0; c < 256; ++c) {
 
60
        flags = 0;
 
61
        if (c % 20 == 0)
 
62
            printf("\n    ");
 
63
 
 
64
        /* escape_shell_cmd */
 
65
#if defined(WIN32) || defined(OS2)
 
66
        /* Win32/OS2 have many of the same vulnerable characters
 
67
         * as Unix sh, plus the carriage return and percent char.
 
68
         * The proper escaping of these characters varies from unix
 
69
         * since Win32/OS2 use carets or doubled-double quotes,
 
70
         * and neither lf nor cr can be escaped.  We escape unix
 
71
         * specific as well, to assure that cross-compiled unix
 
72
         * applications behave similiarly when invoked on win32/os2.
 
73
         *
 
74
         * Rem please keep in-sync with apr's list in win32/filesys.c
 
75
         */
 
76
        if (c && strchr("&;`'\"|*?~<>^()[]{}$\\\n\r%", c)) {
 
77
            flags |= T_ESCAPE_SHELL_CMD;
 
78
        }
 
79
#else
 
80
        if (c && strchr("&;`'\"|*?~<>^()[]{}$\\\n", c)) {
 
81
            flags |= T_ESCAPE_SHELL_CMD;
 
82
        }
 
83
#endif
 
84
 
 
85
        if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:@&=~", c)) {
 
86
            flags |= T_ESCAPE_PATH_SEGMENT;
 
87
        }
 
88
 
 
89
        if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:@&=/~", c)) {
 
90
            flags |= T_OS_ESCAPE_PATH;
 
91
        }
 
92
 
 
93
        /* these are the "tspecials" from RFC2068 */
 
94
        if (c && (apr_iscntrl(c) || strchr(" \t()<>@,;:\\/[]?={}", c))) {
 
95
            flags |= T_HTTP_TOKEN_STOP;
 
96
        }
 
97
 
 
98
        /* For logging, escape all control characters,
 
99
         * double quotes (because they delimit the request in the log file)
 
100
         * backslashes (because we use backslash for escaping)
 
101
         * and 8-bit chars with the high bit set
 
102
         */
 
103
        if (c && (!apr_isprint(c) || c == '"' || c == '\\' || apr_iscntrl(c))) {
 
104
            flags |= T_ESCAPE_LOGITEM;
 
105
        }
 
106
 
 
107
        /* For forensic logging, escape all control characters, top bit set,
 
108
         * :, | (used as delimiters) and % (used for escaping).
 
109
         */
 
110
        if (!apr_isprint(c) || c == ':' || c == '|' || c == '%'
 
111
            || apr_iscntrl(c) || !c) {
 
112
            flags |= T_ESCAPE_FORENSIC;
 
113
        }
 
114
 
 
115
        printf("%u%c", flags, (c < 255) ? ',' : ' ');
 
116
    }
 
117
 
 
118
    printf("\n};\n");
 
119
 
 
120
    return 0;
 
121
}