changeset 7171:2e60288f0d75 HEAD

Previous garbage fix was still incorrect. Fixed it and also changed extensions to be unsigned char* so it can't be accidentally used as a normal string.
author Timo Sirainen <tss@iki.fi>
date Sat, 19 Jan 2008 09:14:50 +0200
parents 36092ec27396
children 097fe25ab218
files src/lib-storage/index/maildir/maildir-uidlist.c
diffstat 1 files changed, 18 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Sat Jan 19 09:08:22 2008 +0200
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Sat Jan 19 09:14:50 2008 +0200
@@ -58,7 +58,7 @@
 	uint32_t uid;
 	uint32_t flags;
 	char *filename;
-	char *extensions; /* <data>\0[<data>\0 ...]\0 */
+	unsigned char *extensions; /* <data>\0[<data>\0 ...]\0 */
 };
 ARRAY_DEFINE_TYPE(maildir_uidlist_rec_p, struct maildir_uidlist_rec *);
 
@@ -797,7 +797,8 @@
 {
 	const struct maildir_uidlist_rec *rec;
 	unsigned int idx;
-	const char *p, *value;
+	const unsigned char *p;
+	const char *value;
 
 	rec = maildir_uidlist_lookup_rec(uidlist, uid, &idx);
 	if (rec == NULL || rec->extensions == NULL)
@@ -807,9 +808,9 @@
 	while (*p != '\0') {
 		/* <key><value>\0 */
 		if (*p == (char)key)
-			return p + 1;
+			return (const char *)p + 1;
 
-		p += strlen(p) + 1;
+		p += strlen((const char *)p) + 1;
 	}
 	return NULL;
 }
@@ -846,7 +847,7 @@
 {
 	struct maildir_uidlist_rec *rec;
 	unsigned int idx;
-	const char *p;
+	const unsigned char *p;
 	buffer_t *buf;
 	unsigned int len;
 
@@ -869,7 +870,7 @@
 		p = rec->extensions;
 		while (*p != '\0') {
 			/* <key><value>\0 */
-			len = strlen(p) + 1;
+			len = strlen((const char *)p) + 1;
 			if (*p != (char)key)
 				buffer_append(buf, p, len);
 			p += len;
@@ -903,7 +904,8 @@
 	struct ostream *output;
 	struct maildir_uidlist_rec *rec;
 	string_t *str;
-	const char *p;
+	const unsigned char *p;
+	unsigned int len;
 	int ret;
 
 	i_assert(fd != -1);
@@ -936,9 +938,10 @@
 		str_printfa(str, "%u", rec->uid);
 		if (rec->extensions != NULL) {
 			for (p = rec->extensions; *p != '\0'; ) {
+				len = strlen((const char *)p);
 				str_append_c(str, ' ');
-				str_append(str, p);
-				p += strlen(p) + 1;
+				str_append_n(str, p, len);
+				p += len + 1;
 			}
 		}
 		str_printfa(str, " :%s\n", rec->filename);
@@ -1210,23 +1213,21 @@
 	ctx->finished = FALSE;
 }
 
-static char *ext_dup(pool_t pool, const char *extensions)
+static unsigned char *ext_dup(pool_t pool, const unsigned char *extensions)
 {
-	char *ret;
+	unsigned char *ret;
 
 	if (extensions == NULL)
 		return NULL;
 
 	T_FRAME_BEGIN {
-		string_t *str = t_str_new(64);
 		unsigned int len;
 
-		while (*extensions != '\0') {
-			len = strlen(extensions);
-			str_append_n(str, extensions, len);
-			extensions += len + 1;
+		for (len = 0; extensions[len] != '\0'; len++) {
+			while (extensions[len] != '\0') len++;
 		}
-		ret = p_strdup(pool, str_c(str));
+		ret = p_malloc(pool, len + 1);
+		memcpy(ret, extensions, len);
 	} T_FRAME_END;
 	return ret;
 }