From 513b3863d999f91b47d7e9f26710390db55f9463 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 14 Jan 2016 14:28:37 +0100 Subject: ui-shared: prevent malicious filename from injecting headers --- html.c | 26 ++++++++++++++++++++++++++ html.h | 1 + ui-shared.c | 8 +++++--- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/html.c b/html.c index 959148c..d89df3a 100644 --- a/html.c +++ b/html.c @@ -239,6 +239,32 @@ void html_url_arg(const char *txt) html(txt); } +void html_header_arg_in_quotes(const char *txt) +{ + const char *t = txt; + while (t && *t) { + unsigned char c = *t; + const char *e = NULL; + if (c == '\\') + e = "\\\\"; + else if (c == '\r') + e = "\\r"; + else if (c == '\n') + e = "\\n"; + else if (c == '"') + e = "\\\""; + if (e) { + html_raw(txt, t - txt); + html(e); + txt = t + 1; + } + t++; + } + if (t != txt) + html(txt); + +} + void html_hidden(const char *name, const char *value) { html("