summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-05-09 18:49:49 +0200
committerLeah Neukirchen <leah@vuxu.org>2020-05-09 18:49:49 +0200
commit9aa5da97d70cdf10a8ccb2ffdb9ccbcb2784c6ed (patch)
tree8631fe897b963180bf25bb18ca082eb39a01a41d
parent1910c5c58090187f77cfefd5cde7c279d658bb85 (diff)
downloadhittpd-9aa5da97d70cdf10a8ccb2ffdb9ccbcb2784c6ed.tar.gz
hittpd-9aa5da97d70cdf10a8ccb2ffdb9ccbcb2784c6ed.tar.xz
hittpd-9aa5da97d70cdf10a8ccb2ffdb9ccbcb2784c6ed.zip
escape path in accesslog
-rw-r--r--hittpd.c13
1 files 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));
 }