[dovecot-cvs] dovecot/src/lib-index/maildir maildir-index.c,1.15,1.16

cras at procontrol.fi cras at procontrol.fi
Sun Dec 8 07:23:10 EET 2002


Update of /home/cvs/dovecot/src/lib-index/maildir
In directory danu:/tmp/cvs-serv19285/lib-index/maildir

Modified Files:
	maildir-index.c 
Log Message:
Added buffer API. Point is to hide all buffer writing behind this API which
verifies that nothing overflows. Much better than doing the same checks all
around the code, even if it is slightly slower.

Buffer reading is still mostly done directly, that isn't such a big security
risk and I can't think of a reasonable API for it anyway.



Index: maildir-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/maildir/maildir-index.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- maildir-index.c	25 Nov 2002 19:02:49 -0000	1.15
+++ maildir-index.c	8 Dec 2002 05:23:08 -0000	1.16
@@ -1,6 +1,7 @@
 /* Copyright (C) 2002 Timo Sirainen */
 
 #include "lib.h"
+#include "temp-string.h"
 #include "maildir-index.h"
 #include "mail-index-data.h"
 #include "mail-index-util.h"
@@ -55,8 +56,8 @@
 
 const char *maildir_filename_set_flags(const char *fname, MailFlags flags)
 {
+	TempString *flags_str;
 	const char *info, *oldflags;
-	char *flags_buf, *p;
 	int i, nextflag;
 
 	/* remove the old :info from file name, and get the old flags */
@@ -73,9 +74,8 @@
 
 	/* insert the new flags between old flags. flags must be sorted by
 	   their ASCII code. unknown flags are kept. */
-	flags_buf = t_malloc(MAIL_FLAGS_COUNT+strlen(oldflags)+1);
-	p = flags_buf;
-
+	flags_str = t_string_new(MAIL_FLAGS_COUNT+strlen(oldflags)+4);
+	t_string_append(flags_str, ":2,");
 	for (;;) {
 		/* skip all known flags */
 		while (*oldflags == 'D' || *oldflags == 'F' ||
@@ -88,30 +88,30 @@
 			(unsigned char) *oldflags;
 
 		if ((flags & MAIL_DRAFT) && nextflag > 'D') {
-			*p++ = 'D';
+			t_string_append_c(flags_str, 'D');
 			flags &= ~MAIL_DRAFT;
 		}
 		if ((flags & MAIL_FLAGGED) && nextflag > 'F') {
-			*p++ = 'F';
+			t_string_append_c(flags_str, 'F');
 			flags &= ~MAIL_FLAGGED;
 		}
 		if ((flags & MAIL_ANSWERED) && nextflag > 'R') {
-			*p++ = 'R';
+			t_string_append_c(flags_str, 'R');
 			flags &= ~MAIL_ANSWERED;
 		}
 		if ((flags & MAIL_SEEN) && nextflag > 'S') {
-			*p++ = 'S';
+			t_string_append_c(flags_str, 'S');
 			flags &= ~MAIL_SEEN;
 		}
 		if ((flags & MAIL_DELETED) && nextflag > 'T') {
-			*p++ = 'T';
+			t_string_append_c(flags_str, 'T');
 			flags &= ~MAIL_DELETED;
 		}
 
 		if ((flags & MAIL_CUSTOM_FLAGS_MASK) && nextflag > 'a') {
 			for (i = 0; i < MAIL_CUSTOM_FLAGS_COUNT; i++) {
 				if (flags & (1 << (i + MAIL_CUSTOM_FLAG_1_BIT)))
-					*p++ = 'a' + i;
+					t_string_append_c(flags_str, 'a' + i);
 			}
 			flags &= ~MAIL_CUSTOM_FLAGS_MASK;
 		}
@@ -119,18 +119,16 @@
 		if (*oldflags == '\0' || *oldflags == ',')
 			break;
 
-		*p++ = *oldflags++;
+		t_string_append_c(flags_str, *oldflags);
 	}
 
 	if (*oldflags == ',') {
 		/* another flagset, we don't know about these, just keep them */
 		while (*oldflags != '\0')
-			*p++ = *oldflags++;
+			t_string_append_c(flags_str, *oldflags++);
 	}
 
-	*p = '\0';
-
-	return t_strconcat(fname, ":2,", flags_buf, NULL);
+	return flags_str->str;
 }
 
 MailIndex *maildir_index_alloc(const char *dir)




More information about the dovecot-cvs mailing list