|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef CROSS_COMPILE
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <ctype.h>
|
|
Packit |
90a5c9 |
#define apr_isalnum(c) (isalnum(((unsigned char)(c))))
|
|
Packit |
90a5c9 |
#define apr_isalpha(c) (isalpha(((unsigned char)(c))))
|
|
Packit |
90a5c9 |
#define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
|
|
Packit |
90a5c9 |
#define apr_isprint(c) (isprint(((unsigned char)(c))))
|
|
Packit |
90a5c9 |
#define APR_HAVE_STDIO_H 1
|
|
Packit |
90a5c9 |
#define APR_HAVE_STRING_H 1
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr.h"
|
|
Packit |
90a5c9 |
#include "apr_lib.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if defined(WIN32) || defined(OS2)
|
|
Packit |
90a5c9 |
#define NEED_ENHANCED_ESCAPES
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if APR_HAVE_STDIO_H
|
|
Packit |
90a5c9 |
#include <stdio.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
#if APR_HAVE_STRING_H
|
|
Packit |
90a5c9 |
#include <string.h>
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* A bunch of functions in util.c scan strings looking for certain characters.
|
|
Packit |
90a5c9 |
* To make that more efficient we encode a lookup table.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
#define T_ESCAPE_SHELL_CMD (0x01)
|
|
Packit |
90a5c9 |
#define T_ESCAPE_PATH_SEGMENT (0x02)
|
|
Packit |
90a5c9 |
#define T_OS_ESCAPE_PATH (0x04)
|
|
Packit |
90a5c9 |
#define T_HTTP_TOKEN_STOP (0x08)
|
|
Packit |
90a5c9 |
#define T_ESCAPE_LOGITEM (0x10)
|
|
Packit |
90a5c9 |
#define T_ESCAPE_FORENSIC (0x20)
|
|
Packit |
90a5c9 |
#define T_ESCAPE_URLENCODED (0x40)
|
|
Packit |
90a5c9 |
#define T_HTTP_CTRLS (0x80)
|
|
Packit |
90a5c9 |
#define T_VCHAR_OBSTEXT (0x100)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int main(int argc, char *argv[])
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned c;
|
|
Packit |
90a5c9 |
unsigned short flags;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("/* this file is automatically generated by gen_test_char, "
|
|
Packit |
90a5c9 |
"do not edit */\n"
|
|
Packit |
90a5c9 |
"#define T_ESCAPE_SHELL_CMD (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_ESCAPE_PATH_SEGMENT (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_OS_ESCAPE_PATH (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_HTTP_TOKEN_STOP (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_ESCAPE_LOGITEM (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_ESCAPE_FORENSIC (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_ESCAPE_URLENCODED (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_HTTP_CTRLS (%u)\n"
|
|
Packit |
90a5c9 |
"#define T_VCHAR_OBSTEXT (%u)\n"
|
|
Packit |
90a5c9 |
"\n"
|
|
Packit |
90a5c9 |
"static const unsigned short test_char_table[256] = {",
|
|
Packit |
90a5c9 |
T_ESCAPE_SHELL_CMD,
|
|
Packit |
90a5c9 |
T_ESCAPE_PATH_SEGMENT,
|
|
Packit |
90a5c9 |
T_OS_ESCAPE_PATH,
|
|
Packit |
90a5c9 |
T_HTTP_TOKEN_STOP,
|
|
Packit |
90a5c9 |
T_ESCAPE_LOGITEM,
|
|
Packit |
90a5c9 |
T_ESCAPE_FORENSIC,
|
|
Packit |
90a5c9 |
T_ESCAPE_URLENCODED,
|
|
Packit |
90a5c9 |
T_HTTP_CTRLS,
|
|
Packit |
90a5c9 |
T_VCHAR_OBSTEXT);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (c = 0; c < 256; ++c) {
|
|
Packit |
90a5c9 |
flags = 0;
|
|
Packit |
90a5c9 |
if (c % 8 == 0)
|
|
Packit |
90a5c9 |
printf("\n ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* escape_shell_cmd */
|
|
Packit |
90a5c9 |
#ifdef NEED_ENHANCED_ESCAPES
|
|
Packit |
90a5c9 |
/* Win32/OS2 have many of the same vulnerable characters
|
|
Packit |
90a5c9 |
* as Unix sh, plus the carriage return and percent char.
|
|
Packit |
90a5c9 |
* The proper escaping of these characters varies from unix
|
|
Packit |
90a5c9 |
* since Win32/OS2 use carets or doubled-double quotes,
|
|
Packit |
90a5c9 |
* and neither lf nor cr can be escaped. We escape unix
|
|
Packit |
90a5c9 |
* specific as well, to assure that cross-compiled unix
|
|
Packit |
90a5c9 |
* applications behave similarly when invoked on win32/os2.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Rem please keep in-sync with apr's list in win32/filesys.c
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (c && strchr("&;`'\"|*?~<>^()[]{}$\\\n\r%", c)) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_SHELL_CMD;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
if (c && strchr("&;`'\"|*?~<>^()[]{}$\\\n", c)) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_SHELL_CMD;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:@&=~", c)) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_PATH_SEGMENT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:;@&=/~", c)) {
|
|
Packit |
90a5c9 |
flags |= T_OS_ESCAPE_PATH;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!apr_isalnum(c) && !strchr(".-*_ ", c)) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_URLENCODED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Stop for any non-'token' character, including ctrls, obs-text,
|
|
Packit |
90a5c9 |
* and "tspecials" (RFC2068) a.k.a. "separators" (RFC2616), which
|
|
Packit |
90a5c9 |
* is easer to express as characters remaining in the ASCII token set
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!c || !(apr_isalnum(c) || strchr("!#$%&'*+-.^_`|~", c))) {
|
|
Packit |
90a5c9 |
flags |= T_HTTP_TOKEN_STOP;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Catch CTRLs other than VCHAR, HT and SP, and obs-text (RFC7230 3.2)
|
|
Packit |
90a5c9 |
* This includes only the C0 plane, not C1 (which is obs-text itself.)
|
|
Packit |
90a5c9 |
* XXX: We should verify that all ASCII C0 ctrls/DEL corresponding to
|
|
Packit |
90a5c9 |
* the current EBCDIC translation are captured, and ASCII C1 ctrls
|
|
Packit |
90a5c9 |
* corresponding are all permitted (as they fall under obs-text rule)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!c || (apr_iscntrl(c) && c != '\t')) {
|
|
Packit |
90a5c9 |
flags |= T_HTTP_CTRLS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* From RFC3986, the specific sets of gen-delims, sub-delims (2.2),
|
|
Packit |
90a5c9 |
* and unreserved (2.3) that are possible somewhere within a URI.
|
|
Packit |
90a5c9 |
* Spec requires all others to be %XX encoded, including obs-text.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (c && !apr_iscntrl(c) && c != ' ') {
|
|
Packit |
90a5c9 |
flags |= T_VCHAR_OBSTEXT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* For logging, escape all control characters,
|
|
Packit |
90a5c9 |
* double quotes (because they delimit the request in the log file)
|
|
Packit |
90a5c9 |
* backslashes (because we use backslash for escaping)
|
|
Packit |
90a5c9 |
* and 8-bit chars with the high bit set
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (c && (!apr_isprint(c) || c == '"' || c == '\\' || apr_iscntrl(c))) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_LOGITEM;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* For forensic logging, escape all control characters, top bit set,
|
|
Packit |
90a5c9 |
* :, | (used as delimiters) and % (used for escaping).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!apr_isprint(c) || c == ':' || c == '|' || c == '%'
|
|
Packit |
90a5c9 |
|| apr_iscntrl(c) || !c) {
|
|
Packit |
90a5c9 |
flags |= T_ESCAPE_FORENSIC;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("0x%03x%c", flags, (c < 255) ? ',' : ' ');
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\n};\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return 0;
|
|
Packit |
90a5c9 |
}
|