aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-31 21:27:30 +0100
committerPřemysl Eric Janouch <p@janouch.name>2020-10-31 21:28:29 +0100
commit960420df3e7ba3e399fbc73001d79b5d1cf10a1d (patch)
treeb558b9930dfd95fd261ad2444dd7deafa03ccf16
parentd71c47f8ce7aecdc4856630e9d73a48912be68c1 (diff)
downloadliberty-960420df3e7ba3e399fbc73001d79b5d1cf10a1d.tar.gz
liberty-960420df3e7ba3e399fbc73001d79b5d1cf10a1d.tar.xz
liberty-960420df3e7ba3e399fbc73001d79b5d1cf10a1d.zip
Escape DEL character in config_item_write_string()
-rw-r--r--liberty.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/liberty.c b/liberty.c
index 9705081..e323149 100644
--- a/liberty.c
+++ b/liberty.c
@@ -4708,13 +4708,15 @@ config_item_write_string (struct str *output, const struct str *s)
for (size_t i = 0; i < s->len; i++)
{
unsigned char c = s->str[i];
- if (c == '\n') str_append (output, "\\n");
- else if (c == '\r') str_append (output, "\\r");
- else if (c == '\t') str_append (output, "\\t");
- else if (c == '\\') str_append (output, "\\\\");
- else if (c == '"') str_append (output, "\\\"");
- else if (c < 32) str_append_printf (output, "\\x%02x", c);
- else str_append_c (output, c);
+ if (c == '\n') str_append (output, "\\n");
+ else if (c == '\r') str_append (output, "\\r");
+ else if (c == '\t') str_append (output, "\\t");
+ else if (c == '\\') str_append (output, "\\\\");
+ else if (c == '"') str_append (output, "\\\"");
+ else if (iscntrl_ascii (c))
+ str_append_printf (output, "\\x%02x", c);
+ else
+ str_append_c (output, c);
}
str_append_c (output, '"');
}