static const char *log_remote_host(request_rec *r, char *a)
{
- return ap_get_remote_host(r->connection, r->per_dir_config,
- REMOTE_NAME, NULL);
+ return ap_escape_logitem(r->pool, ap_get_remote_host(r->connection,
+ r->per_dir_config,
+ REMOTE_NAME, NULL));
}
static const char *log_remote_address(request_rec *r, char *a)
static const char *log_remote_logname(request_rec *r, char *a)
{
- return ap_get_remote_logname(r);
+ return ap_escape_logitem(r->pool, ap_get_remote_logname(r));
}
static const char *log_remote_user(request_rec *r, char *a)
else if (strlen(rvalue) == 0) {
rvalue = "\"\"";
}
+ else {
+ rvalue = ap_escape_logitem(r->pool, rvalue);
+ }
+
return rvalue;
}
* (note the truncation before the protocol string for HTTP/0.9 requests)
* (note also that r->the_request contains the unmodified request)
*/
- return (r->parsed_uri.password)
- ? apr_pstrcat(r->pool, r->method, " ",
- apr_uri_unparse(r->pool, &r->parsed_uri, 0),
- r->assbackwards ? NULL : " ", r->protocol, NULL)
- : r->the_request;
+ return ap_escape_logitem(r->pool,
+ (r->parsed_uri.password)
+ ? apr_pstrcat(r->pool, r->method, " ",
+ apr_uri_unparse(r->pool,
+ &r->parsed_uri, 0),
+ r->assbackwards ? NULL : " ",
+ r->protocol, NULL)
+ : r->the_request);
}
static const char *log_request_file(request_rec *r, char *a)
{
- return r->filename;
+ return ap_escape_logitem(r->pool, r->filename);
}
static const char *log_request_uri(request_rec *r, char *a)
{
- return r->uri;
+ return ap_escape_logitem(r->pool, r->uri);
}
static const char *log_request_method(request_rec *r, char *a)
{
- return r->method;
+ return ap_escape_logitem(r->pool, r->method);
}
static const char *log_request_protocol(request_rec *r, char *a)
{
- return r->protocol;
+ return ap_escape_logitem(r->pool, r->protocol);
}
static const char *log_request_query(request_rec *r, char *a)
{
- return (r->args != NULL) ? apr_pstrcat(r->pool, "?", r->args, NULL)
- : "";
+ return (r->args) ? apr_pstrcat(r->pool, "?",
+ ap_escape_logitem(r->pool, r->args), NULL)
+ : "";
}
static const char *log_status(request_rec *r, char *a)
{
static const char *log_header_in(request_rec *r, char *a)
{
- return apr_table_get(r->headers_in, a);
+ return ap_escape_logitem(r->pool, apr_table_get(r->headers_in, a));
}
static const char *log_header_out(request_rec *r, char *a)
cp = ap_field_noparam(r->pool, r->content_type);
}
if (cp) {
- return cp;
+ return ap_escape_logitem(r->pool, cp);
}
- return apr_table_get(r->err_headers_out, a);
+ return ap_escape_logitem(r->pool, apr_table_get(r->err_headers_out, a));
}
static const char *log_note(request_rec *r, char *a)
{
- return apr_table_get(r->notes, a);
+ return ap_escape_logitem(r->pool, apr_table_get(r->notes, a));
}
static const char *log_env_var(request_rec *r, char *a)
{
- return apr_table_get(r->subprocess_env, a);
+ return ap_escape_logitem(r->pool, apr_table_get(r->subprocess_env, a));
}
static const char *log_cookie(request_rec *r, char *a)
if (end_cookie) {
*end_cookie = '\0';
}
- return cookie;
+ return ap_escape_logitem(r->pool, cookie);
}
}
return NULL;
*/
static const char *log_virtual_host(request_rec *r, char *a)
{
- return r->server->server_hostname;
+ return ap_escape_logitem(r->pool, r->server->server_hostname);
}
static const char *log_server_port(request_rec *r, char *a)
*/
static const char *log_server_name(request_rec *r, char *a)
{
- return ap_get_server_name(r);
+ return ap_escape_logitem(r->pool, ap_get_server_name(r));
}
static const char *log_child_pid(request_rec *r, char *a)
#define T_ESCAPE_PATH_SEGMENT (0x02)
#define T_OS_ESCAPE_PATH (0x04)
#define T_HTTP_TOKEN_STOP (0x08)
+#define T_ESCAPE_LOGITEM (0x10)
int main(int argc, char *argv[])
{
"#define T_ESCAPE_PATH_SEGMENT (%u)\n"
"#define T_OS_ESCAPE_PATH (%u)\n"
"#define T_HTTP_TOKEN_STOP (%u)\n"
+ "#define T_ESCAPE_LOGITEM (%u)\n"
"\n"
"static const unsigned char test_char_table[256] = {\n"
" 0,",
T_ESCAPE_SHELL_CMD,
T_ESCAPE_PATH_SEGMENT,
T_OS_ESCAPE_PATH,
- T_HTTP_TOKEN_STOP);
+ T_HTTP_TOKEN_STOP,
+ T_ESCAPE_LOGITEM);
/* we explicitly dealt with NUL above
* in case some strchr() do bogosity with it */
flags |= T_HTTP_TOKEN_STOP;
}
- printf("%u%c", flags, (c < 255) ? ',' : ' ');
+ /* For logging, escape all control characters,
+ * double quotes (because they delimit the request in the log file)
+ * backslashes (because we use backslash for escaping)
+ * and 8-bit chars with the high bit set
+ */
+ if (!apr_isprint(c) || c == '"' || c == '\\' || apr_iscntrl(c)) {
+ flags |= T_ESCAPE_LOGITEM;
+ }
+ printf("%u%c", flags, (c < 255) ? ',' : ' ');
}
printf("\n};\n");