From 9aa5da97d70cdf10a8ccb2ffdb9ccbcb2784c6ed Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 9 May 2020 18:49:49 +0200 Subject: escape path in accesslog --- hittpd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hittpd.c b/hittpd.c index 7ea8592..33826f1 100644 --- a/hittpd.c +++ b/hittpd.c @@ -258,11 +258,18 @@ accesslog(http_parser *p, int status) // REMOTEHOST - - [DD/MON/YYYY:HH:MM:SS -TZ] "METHOD PATH" STATUS BYTES // ? REFERER USER_AGENT - printf("%s - - %s \"%s %s\" %d %jd\n", + printf("%s - - %s \"%s ", peername(p), buf, - http_method_str(p->method), - data->path, + http_method_str(p->method)); + + for (char *s = data->path; *s; s++) + if (*s < 32 || *s >= 127 || *s == '"') + printf("%%%02x", *s); + else + putchar(*s); + + printf("\" %d %jd\n", status, p->method == HTTP_HEAD ? 0 : content_length(data)); } -- cgit 1.4.1