From 051f35ba6c65cc022727e18fa8b5aa13f2fc0e5c Mon Sep 17 00:00:00 2001 From: glen Date: Fri, 28 May 2010 15:36:44 +0000 Subject: - Print double quotes properly when dumping config file (fixes #1806) git-svn-id: svn://svn.lighttpd.net/lighttpd/trunk@2726 152afb58-edef-0310-8abb-c4023f1b3aa9 --- NEWS | 1 + src/data_string.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 0b79b8e9..ea49e397 100644 --- a/NEWS +++ b/NEWS @@ -161,6 +161,7 @@ NEWS * Fix select() backend under high load (off-by-one, noticed by Manuel Scharf in a forum thread) * Append to previous buffer in con read (fixes #2147, found by liming, CVE-2010-0295) * Fix handling return value of SSL_CTX_set_options (fixes #2157, thx mlcreech) + * Print double quotes properly when dumping config file (fixes #1806) - 1.5.0-r19.. - * -F option added for spawn-fcgi diff --git a/src/data_string.c b/src/data_string.c index 5b2678d8..a4bc31cf 100644 --- a/src/data_string.c +++ b/src/data_string.c @@ -70,8 +70,25 @@ static int data_response_insert_dup(data_unset *dst, data_unset *src) { static void data_string_print(const data_unset *d, int depth) { data_string *ds = (data_string *)d; UNUSED(depth); + unsigned int i = 0; - fprintf(stdout, "\"%s\"", ds->value->used ? ds->value->ptr : ""); + // empty and uninitialized strings + if (ds->value->used < 1) { + fputs("\"\"", stdout); + return; + } + + // print out the string as is, except prepend " with backslash + putc('"', stdout); + for (i = 0; i < ds->value->used - 1; i++) { + unsigned char c = ds->value->ptr[i]; + if (c == '"') { + fputs("\\\"", stdout); + } else { + putc(c, stdout); + } + } + putc('"', stdout); } -- cgit v1.2.1