dovecot-2.2: dict-file: Use tabescaping for keys and values to a...

dovecot at dovecot.org dovecot at dovecot.org
Tue Apr 14 06:59:24 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/93dab55ae36e
changeset: 18403:93dab55ae36e
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Apr 14 09:58:01 2015 +0300
description:
dict-file: Use tabescaping for keys and values to allow LFs in them.
Although this makes the format slightly incompatible, it's doubtful anybody
is using dict values containing \001 characters.

diffstat:

 src/lib-dict/dict-file.c |  18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 635f9c7d5991 -r 93dab55ae36e src/lib-dict/dict-file.c
--- a/src/lib-dict/dict-file.c	Mon Apr 13 20:38:10 2015 +0300
+++ b/src/lib-dict/dict-file.c	Tue Apr 14 09:58:01 2015 +0300
@@ -3,6 +3,8 @@
 #include "lib.h"
 #include "array.h"
 #include "hash.h"
+#include "str.h"
+#include "strescape.h"
 #include "home-expand.h"
 #include "mkdir-parents.h"
 #include "file-lock.h"
@@ -177,12 +179,12 @@
 
 		while ((key = i_stream_read_next_line(input)) != NULL) {
 			/* strdup() before the second read */
-			key = p_strdup(dict->hash_pool, key);
+			key = str_tabunescape(p_strdup(dict->hash_pool, key));
 
 			if ((value = i_stream_read_next_line(input)) == NULL)
 				break;
 
-			value = p_strdup(dict->hash_pool, value);
+			value = str_tabunescape(p_strdup(dict->hash_pool, value));
 			hash_table_insert(dict->hash, key, value);
 		}
 		i_stream_destroy(&input);
@@ -501,6 +503,7 @@
 	struct hash_iterate_context *iter;
 	struct ostream *output;
 	char *key, *value;
+	string_t *str;
 	int fd = -1;
 
 	*atomic_inc_not_found_r = FALSE;
@@ -558,11 +561,14 @@
 	output = o_stream_create_fd(fd, 0, FALSE);
 	o_stream_cork(output);
 	iter = hash_table_iterate_init(dict->hash);
+	str = t_str_new(256);
 	while (hash_table_iterate(iter, dict->hash, &key, &value)) {
-		o_stream_nsend_str(output, key);
-		o_stream_nsend(output, "\n", 1);
-		o_stream_nsend_str(output, value);
-		o_stream_nsend(output, "\n", 1);
+		str_truncate(str, 0);
+		str_append_tabescaped(str, key);
+		str_append_c(str, '\n');
+		str_append_tabescaped(str, value);
+		str_append_c(str, '\n');
+		o_stream_nsend(output, str_data(str), str_len(str));
 	}
 	hash_table_iterate_deinit(&iter);
 


More information about the dovecot-cvs mailing list